Best way to implement recurring task
gendalus last edited by
I'm currently working on a project what should call an API about every minute (the exact timing is not that important). In order to do it I have a while loop wich is paused after each loop for 60 seconds.
def loop(): while True: update() time.sleep(60) loop()
Is there any better way to do this? It seems, that when I'm running the script and the script is actually paused you can't stop the script with tapping on the [x]. It seems to be waiting for the sleep to end and is terminating after that.
omz last edited by
sleepcan't be interrupted. If you want to sleep for such a long time, I would recommend calling it multiple times instead:
for i in xrange(60): time.sleep(1)
JonB last edited by
If this is from a ui, you could use ui.delay at the end of an function, which calls itself. Cancel would be handled by
ui.cancel_delays(), either by button, or from
will_close, or by checking