1234567891011121314151617181920212223 |
- import threading
- class ThreadManager:
- """
- Manages multiple threads used to execute given handler tasks.
- """
- def __init__(self, handlers):
- self.handlers = handlers
- self.threads = []
- def start(self):
- for handler in self.handlers:
- thread = threading.Thread(target=handler.run)
- self.threads.append(thread)
- thread.start()
- def stop(self):
- for handler in self.handlers:
- handler.stop_event.set()
- for thread in self.threads:
- thread.join()
|