Added timer module
This commit is contained in:
parent
205b3e483d
commit
9013e3516f
28
hc_spider/timer.py
Normal file
28
hc_spider/timer.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
from hc_spider.model import SharedObjects
|
||||||
|
|
||||||
|
|
||||||
|
class Timer(threading.Thread):
|
||||||
|
_shared_objects: SharedObjects
|
||||||
|
|
||||||
|
def __init__(self, **kwargs) -> None:
|
||||||
|
self._shared_objects = SharedObjects(**kwargs)
|
||||||
|
super().__init__()
|
||||||
|
self.daemon = True
|
||||||
|
self.name = "Timer"
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
print(f"{self.name} started with pid [{os.getpid()}]")
|
||||||
|
runtime = self._shared_objects.config.get("timer_runtime", 0)
|
||||||
|
if runtime == 0:
|
||||||
|
return
|
||||||
|
time.sleep(runtime)
|
||||||
|
print(f"{self.name} timer reached the end of runtime, exiting")
|
||||||
|
self._shared_objects.shutdown_event.set()
|
||||||
|
print(f"[{self.name}] is shutting down", flush=True)
|
||||||
|
|
||||||
|
def __del__(self) -> None:
|
||||||
|
print(f"[{self.name}] exited")
|
Loading…
x
Reference in New Issue
Block a user