Python program starts running again after pc wakes up?
I am running a python program that takes a few hours to complete. If I close the lid of my laptop (ie I put it to sleep), will the program start again when I reopen my laptop? It's been a few hours already and I have to leave soon (so I need to close my laptop) but I don't want to start the process again. Will the program start from the exact same point? What is the default behaviour in Ubuntu 16.04?
Fyi, I am running a cross validation for a classifier which does not use any network resources - only CPU and RAM.
The simple answer is yes but the truth is a little more complicated.
Yes the application will still be running; it'll resume with the rest of the system's processes. There are, however, stateful things like network connections and graphics driver states. These need to reinitialise with external hardware and that may mean some added network latency to begin with, or even a proper disconnect-reconnect (as happens to me on Ethernet). In particularly bad situations —definitely exceptions to the rule— the entire desktop environment can crash and restart.
So I can't guarantee what'll happen to you. If your application will crash if it loses network connectivity, there might be an issue. If it's doing rendering or CUDA/OpenCL stuff, it might break.
If it's just a plain CPU/disk stuff, it should be fine.
But who knows for certain. Computers make fools of us all.
Good luck.
When you suspend the system (put it to sleep), it stores all its CPU registers etc. that represent what it's currently doing in your RAM and then powers down most components except those that preserve RAM contents and those that are needed to wake the computer up again later (input devices, etc).
When you wake it up later again, the previous state gets restored and the computer continues exactly at the point where you had suspended it.
That is the main concept, of course in reality there happens more because all this doesn't magically happen when snipping your fingers. There are many system scripts etc involved that get run before suspending and after waking up.
However, unless you manually set something up to do that, suspending the computer will never close any running applications. There is a small risk that something crashes in the process, but normally if it worked once, it works always.
If the laptop goes to sleep (=suspend), definitely yes. The only thing that can be disrupted are network connections or similar, real-time thing; in that case, it depends if the running program is safely written to accept temporary failures and recover.
If the laptop powers off, definitely no --- there is an option somewhere in the Control Panel to decide between the two behaviors, I think.