Appnope
Appnope is a small Python library for macOS (10.9 and later) that disables App Nap for the current process. It is primarily used in long-running Python applications and interactive environments like Jupyter notebooks to prevent them from being suspended when in the background. The current version is 0.1.4, and the library is in maintenance, receiving updates mainly for compatibility.
Common errors
-
ModuleNotFoundError: No module named 'appnope'
cause The 'appnope' module is not installed in the current Python environment.fixInstall the module using pip: 'pip install appnope'. -
ImportError: No module named 'appnope'
cause The 'appnope' module is not installed or not accessible in the current Python environment.fixEnsure the module is installed with 'pip install appnope' and that the correct Python environment is active. -
AttributeError: module 'appnope' has no attribute 'nope'
cause The 'appnope' module is not correctly installed or is outdated.fixReinstall the module using 'pip install --force-reinstall appnope'. -
appnope not having any effect or raising platform-specific errors on non-macOS systems
cause 'appnope' is a macOS-specific library designed to disable App Nap on macOS 10.9 (Mavericks) and later. It will have no functional effect or may raise errors if imported or used on other operating systems (like Windows or Linux) or older macOS versions.fixGuard the import and usage of `appnope` with a platform check: `import sys; if sys.platform == 'darwin': import appnope`. Ensure the target macOS version is 10.9 or newer. -
Jupyter kernel died unexpectedly / Jupyter notebook kernel not connecting (related to appnope)
cause In certain environments, particularly with specific Python versions (e.g., Python 3.6) and macOS versions (e.g., macOS 11.5) in conjunction with Conda, 'appnope' can sometimes interfere with the Jupyter kernel's startup or stability, leading to the kernel dying or failing to connect.fixDisable 'appnope' within the IPython kernel configuration by adding `c.Kernel._darwin_app_nap = False` to your `~/.ipython/profile_default/ipython_kernel_config.py` file.
Warnings
- gotcha Appnope is a macOS-specific library. It will not have any effect or may raise platform-specific errors if run on non-macOS operating systems.
- gotcha App Nap itself only exists on macOS 10.9 (Mavericks) and later. Using `appnope` on older macOS versions will have no effect related to App Nap, though the library might still import.
- gotcha Appnope disables App Nap only for the *current* process. If your Python application spawns child processes (e.g., using `subprocess` or `multiprocessing`), those child processes will not automatically inherit the App Nap disabled state and may still be subject to App Nap.
- gotcha The primary effect of `appnope` occurs immediately upon `import appnope`. It's not a function call that you explicitly make after import (unless you use `set_appnap_enabled`).
Install
-
pip install appnope
Imports
- appnope
import appnope
- set_appnap_enabled
import appnope appnope.set_appnap_enabled(False)
Quickstart
import appnope
import time
print("App Nap is now disabled for this process (macOS 10.9+).")
print("Sleeping for 10 seconds. Check activity monitor if App Nap usually affects this process.")
time.sleep(10)
# To explicitly re-enable or disable App Nap later:
# appnope.set_appnap_enabled(True) # Re-enable App Nap
# appnope.set_appnap_enabled(False) # Disable App Nap again
print("Done. App Nap status remains as last set.")