17

I'm running some Python machine learning programs through Terminal that take hours at a time to finish. If I leave my computer unattended it hibernates - the screen goes off and I have to type in my password again.

When this happens, does my script get cancelled, paused, or continue the same? I would hate to think that my script could be 99% finished, and then gets aborted because my computer went to sleep.

  • To prevent your Mac from falling asleep Caffeine is a useful little tool. – Emil Mar 31 '17 at 13:00
  • 11
    Also, your Mac has a built in tool called caffeinate. If you precede the terminal command with caffeinate, e.g. caffeinate python ..., it will not sleep for the length of this particular command. – 0942v8653 Mar 31 '17 at 13:44
17

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.

  • 1
    While the program will continue to run, depending on the dependencies you might have or the process it's running, it may time out or cause an exception and exit with an error. Easiest example I can think of is network access. If you're doing some network task, it sleeps, the machine resumes, the network is not available, it will probably cause an error. – rovr138 Apr 1 '17 at 15:53
5

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

  • 2
    When it's in display sleep, does that still require a user to logon as normal? – raven Dec 30 '17 at 6:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .