how to run a python script in background in google collab?
This is my first question on stackoverflow (usually my doubts used to get clear from other already asked doubts but this time I did not got my doubt already answered so I am now directly asking it)
I am developing a game which involves some different kinds of mazes and puzzles.And hence for that I am using python for procedural generation.But there is an issue. Neither my PC is powerful enough(duo core) to design big puzzles(small puzzles are fine but for bigger ones it looks like it went for an infinite loop) nor I can keep my PC switched ON for hours just to design some puzzles
Later on I learnt about Google collab. I checked it and my python script was running fine.But I want to run the script in the background(the script should run even if my PC is switched OFF).How can I do this?
Thanks in advance
Solution 1:
colab, keep running your script for about an hour, even after your PC/browser stop accessing colab runtime. After an hour of idle time, the colab resources allocated will be released and your script will stop executing.
Colab resources cannot be held beyond ~9 hours continuously. The runtime will be shutdown/discontinued automatically after a max of about 9 hours.
To run the script in the background, use below code,
#run the script/API in the background
import subprocess
subprocess.Popen(["python", "/content/test.py", "argument1"])