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.
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.")