Reputation: 121
I have currently created a python script that runs when I double click and open it. It then creates/overwrites a geojson file. I would like to automate this script to run every minute. I have used:
import time
while True:
# code goes here
time.sleep(60)
This code works. However, it only works when I have the python file opened up by double clicking it. If I do not have it opened, the code does not run and the file will not be overwritten. Is there a piece of code I can write to tell python to run the code, even if the .py file is not open?
Upvotes: 0
Views: 550
Reputation: 3536
I don't think you can run any code if the computer is off.
You need your script running on a server that is always on.
In any case, I would use a cronjob to start your script every minute. The code you are using only starts sleep after the actual job, so the job does not repeat precisely every minute.
Upvotes: 1