Periodically execute function in thread in real time, every N seconds

Viewed 37023

I have a threaded class whose loop needs to execute 4 times every second. I know that I can do something like

do_stuff()
time.sleep(0.25)

but the problem is that is doesn't account for the time it takes to do_stuff(). Effectively this needs to be a real-time thread. Is there a way to accomplish this? Ideally the thread would still be put to sleep when not executing code.

2 Answers
Related