Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Best way to implement recurring task
-
Hi there,
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.
-
Right now,
sleep
can'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)
-
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 fromwill_close
, or by checkingon_screen
etc.