python - How do I stop a thread with a blocking function call? -
i'm uisng psutil library in thread, posts cpu usage statistics periodically. here's snippet:
class informationthread(threading.thread): def __init__(self, *args, **kwargs): threading.thread.__init__(self) def run(self): while true: cpu = psutil.cpu_percent(interval=600) #this blocking call print cpu i need stop thread can't seem understand how. method cpu_percent blocking function block 600 seconds.
i've been digging around , examples saw relied on tight-loop checked flag see whether loop should interrupted in case, i'm not sure how kill thread.
set interval 0.0 , implement tighter inner loop in can check whether thread should terminate. shouldn't difficult time elapsed time between calls cpu_percent() same 600.
Comments
Post a Comment