def stop_listen(self):
"""Stop listening for events"""
self.set_traps(False)
self.stop_request.set()
nb_threads = len([f for f in self.futures if f.running()])
if nb_threads:
# ack current thread
self.current_cont_event.set()
# wait for current thread to terminate
while [f for f in self.futures if f.running()] == nb_threads:
time.sleep(0.1)
# ack the rest of the threads
while [f for f in self.futures if f.running()]:
if self.queue.full():
(*rest, continue_event) = self.queue.get()
continue_event.set()
# let the threads terminate
time.sleep(0.1)
# wait for threads to exit
wait(self.futures)
评论列表
文章目录