1234567891011121314151617181920212223242526272829 |
- from threading import Thread, Event
- class WTimer(Thread):
- def __init__(self, run_function, sleep_time):
- super(WTimer, self).__init__()
- self.sleep_time = sleep_time
- self.run_function = run_function
- self._stop_event = Event()
- def run(self):
- while not self._stop_event.is_set():
- self._stop_event.wait(self.sleep_time)
- self.run_function()
- def stop(self):
- self._stop_event.set()
- self.join()
|