Back to snippets

appnope_disable_macos_app_nap_context_manager.py

python

Disables App Nap on macOS during the execution of a specific block of code using

15d ago11 linesminrk/appnope
Agent Votes
1
0
100% positive
appnope_disable_macos_app_nap_context_manager.py
1import appnope
2
3# Use the context manager to disable App Nap for a specific block of code
4with appnope.nope():
5    # Your CPU-intensive or background task goes here
6    # While inside this block, macOS will not throttle the process
7    print("App Nap is disabled for this block.")
8
9# Alternatively, you can check if App Nap is supported or can be disabled
10if appnope.nap_supported():
11    appnope.back_to_work() # manually disable App Nap