0

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?

LiamHems
  • 121
  • 7

1 Answers1

1

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.

  • Okay I see what you mean, thank you for your help. I will research cronjob now. – LiamHems Nov 05 '20 at 12:10
  • As I am working on a Windows laptop, I unfortunately do not have cronjob and only task scheduler. I can not seem to get task scheduler working with the script I have for some reason, so is there a script I can write that tells the .py file I have, to repeat the same procedure every minute? I am not worried about if my laptop is turned on/off. Thanks – LiamHems Nov 06 '20 at 16:27
  • Try to follow this tutorial: https://www.esri.com/arcgis-blog/products/product/analytics/scheduling-a-python-script-or-model-to-run-at-a-prescribed-time/ – Stefano Fiorucci - anakin87 Nov 06 '20 at 16:38