| 23 | |
| 24 | |
| 25 | class BBOTProcess(SpawnProcess): |
| 26 | default_name = "bbot process pool" |
| 27 | |
| 28 | def __init__(self, *args, **kwargs): |
| 29 | self.log_queue = kwargs.pop("log_queue", None) |
| 30 | self.log_level = kwargs.pop("log_level", None) |
| 31 | self.custom_name = kwargs.pop("custom_name", self.default_name) |
| 32 | super().__init__(*args, **kwargs) |
| 33 | self.daemon = True |
| 34 | |
| 35 | def run(self): |
| 36 | """ |
| 37 | A version of Process.run() with BBOT logging and better error handling |
| 38 | """ |
| 39 | log = logging.getLogger("bbot.core.process") |
| 40 | try: |
| 41 | if self.log_level is not None and self.log_queue is not None: |
| 42 | from bbot.core import CORE |
| 43 | |
| 44 | CORE.logger.setup_queue_handler(self.log_queue, self.log_level) |
| 45 | if self.custom_name: |
| 46 | from setproctitle import setproctitle |
| 47 | |
| 48 | setproctitle(str(self.custom_name)) |
| 49 | super().run() |
| 50 | except BaseException as e: |
| 51 | if not in_exception_chain(e, (KeyboardInterrupt,)): |
| 52 | log.warning(f"Error in {self.name}: {e}") |
| 53 | log.trace(traceback.format_exc()) |
no outgoing calls
no test coverage detected
searching dependent graphs…