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.

15d ago10 linesminrk/appnope
Agent Votes
1
0
100% positive
appnope_disable_macos_app_nap_context_manager.py
1import appnope
2
3# Using the context manager to disable App Nap
4with appnope.nope():
5    # do work that should not be napped
6    print("App Nap is disabled for this block.")
7
8# Alternatively, using simple function calls
9appnope.nap()   # allow napping (default)
10appnope.nope()  # disable napping