Apple - Do Terminal processes stop if Mac sleeps?

All processes get paused when the system goes to sleep, independent of whether the process is part of macOS, an application or some code you wrote on your own. After the system wakes up again, all processes will continue to run.

PS: Processes which were waiting for network or disk data when going to sleep may run into timeouts though. But that can happen anyway so most processes should be able to handle that anyway.


Note that there is a difference between computer sleep and display sleep (both controlled in the Energy Saver pane of System Preferences). When the display is sleeping but the computer is not, programs on your computer continue to run normally. When your Mac enters computer sleep, programs are paused, and will resume when the computer is awakened (but some programs, especially those that rely on network communications, can't resume seamlessly).


Yes, terminal processes like a python script will stop execution when the machine goes into idle sleep.

To prevent your machine from sleeping without changing the settings you can just use the terminal tool caffeinate. Once called it will prevent the machine from sleeping until you cancel the program using ctrl+c.

You can pass arguments like the process id to caffeinate using the -w flag. You can find out a process id using the top command in the terminal, e.g. caffeinate -w 36388 would prevent the machine from going into sleep until that process is finished.

See the attached link for more information.

https://www.howtogeek.com/245683/how-to-prevent-your-mac-from-sleeping-with-no-additional-software/#:~:text=To%20open%20the%20Terminal%2C%20you,you%20leave%20the%20Terminal%20running.