Feb-02-2021, 11:19 AM
You need to use an event timer. It will run independent of other precesses, and create an event (interrupt) when the terminal time is reached.
here's a quick example:
here's a quick example:
import threading, time def do_work(): print("OK ... I'm doing my work here") def testit(seconds): timer = threading.Event() while True: print(f"delay {seconds} seconds") timer.wait(seconds) do_work() if __name__ == '__main__': testit(2)sample output:
Output:delay 2 seconds
OK ... I'm doing my work heredelay 2 seconds
OK ... I'm doing my work here
delay 2 seconds
OK ... I'm doing my work here
delay 2 seconds
OK ... I'm doing my work here
delay 2 seconds
delay 2 seconds
OK ... I'm doing my work here
delay 2 seconds
OK ... I'm doing my work here
delay 2 seconds