Search code examples
pythonsleep-mode

Python script stops running when screen turns off


I am trying to do a simple bot in Python, I have written the body and I wanted to try it on real data. So I ran it, it runs in an infinite loop and at the end of the loop it sleeps for 6 seconds because it gets data from server and needs to sleep so it does not get kicked from server. Anyway, by the time I sat in front of the PC and was doing my stuff the script was running (I am running it from Windows command prompt) but when I turned off the screen and came back, the script was not running anymore. I have tried this few times with different lengths of the runs of script and always it stopped after i turned off the screen.

  • How to keep python script running once the computer screen is turned off

Solution

  • Check "Power Options" in the Control panel.

    You don't need to worry about the screen locking or turning off as these wont affect running processes in python. However, if your system is set to sleep after a set amount of time you may need to change this to Never. Keep in mind there are separate settings depending on whether or not the system is plugged in.