Is there a quick way to setup a function in python to be executed some time in the future (non-blocking, similar to setTimeout in Javascript)? I have an idea how to do it myself, but would rather use something already done if it's there in a library.
Asked
Active
Viewed 69 times
1 Answers
5
Python has a very different execution model than JavaScript that doesn't prioritize this kind of problem. To solve it, you'll probably need to use threading: https://docs.python.org/2/library/threading.html
Specifically, the Timer
class is probably what you're looking for -- check out the example at the above link.
Be aware, however, that Python's threading is not nearly as full featured as that of other languages, because of a global interpreter lock: What is a global interpreter lock (GIL)?.
-
I know I have to use threading, but I'm feeling lazy at this hour and I was hoping that somebody had the same problem before and there is code I could use directly. If not I'll start working on it tomorrow. – rslite Apr 19 '15 at 03:41
-
@rslite, check out the timer example at the link above. – jwilner Apr 19 '15 at 03:44