Starts the handler's workers. Arguments: workers: Number of workers. max_queue_size: queue size (when full, workers could block on `put()`)
(self, workers=1, max_queue_size=10)
| 627 | return self.stop_signal is not None and not self.stop_signal.is_set() |
| 628 | |
| 629 | def start(self, workers=1, max_queue_size=10): |
| 630 | """Starts the handler's workers. |
| 631 | |
| 632 | Arguments: |
| 633 | workers: Number of workers. |
| 634 | max_queue_size: queue size |
| 635 | (when full, workers could block on `put()`) |
| 636 | """ |
| 637 | if self.use_multiprocessing: |
| 638 | self.executor_fn = self._get_executor_init(workers) |
| 639 | else: |
| 640 | # We do not need the init since it's threads. |
| 641 | self.executor_fn = lambda _: ThreadPool(workers) |
| 642 | self.workers = workers |
| 643 | self.queue = queue.Queue(max_queue_size) |
| 644 | self.stop_signal = threading.Event() |
| 645 | self.run_thread = threading.Thread(target=self._run) |
| 646 | self.run_thread.daemon = True |
| 647 | self.run_thread.start() |
| 648 | |
| 649 | def _send_sequence(self): |
| 650 | """Sends current Iterable to all workers.""" |