Python Equivalent of setInterval()?
问题 Does Python have a function similar to JavaScript's setInterval() ? Thanks 回答1: This might be the correct snippet you were looking for: import threading def set_interval(func, sec): def func_wrapper(): set_interval(func, sec) func() t = threading.Timer(sec, func_wrapper) t.start() return t 回答2: This is a version where you could start and stop. It is not blocking. There is also no glitch as execution time error is not added (important for long time execution with very short interval as audio