I'm currently working on a python script that takes some hours to finish. I'm working in a shared office and I want (if possible) lo lock my mac m1 in order to make sure nobody can access it and at the same time keep the script running.
It can be done manually like so, assuming the system is plugged in throughout:
MacOS 13
MacOS 12
Once you lock your screen now (Apple icon top-left or the power button), your computer should stay awake. Note that if you close the lid, the system will sleep
There's a library just for this purpose*: wakepy.
Since you do not require the screen to be on, you could use the keep.running mode, like this:
from wakepy import keep
with keep.running(on_fail='warn'):
# Call the function that takes a long time.
# You may lock the session and turn the screen off but CPU will keep running
With this you do not have to fiddle with your power settings, and since it's cross-platform you can share your script with your colleagues using Windows or Linux, too.
*full disclosure: I'm the author of the package
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With