Enqueues handlers for _run_handlers() to run. `what` is the Message being handled, and is used for logging purposes. If the background thread with _run_handlers() isn't running yet, starts it.
(self, what, *handlers)
| 1386 | os._exit(1) |
| 1387 | |
| 1388 | def _enqueue_handlers(self, what, *handlers): |
| 1389 | """Enqueues handlers for _run_handlers() to run. |
| 1390 | |
| 1391 | `what` is the Message being handled, and is used for logging purposes. |
| 1392 | |
| 1393 | If the background thread with _run_handlers() isn't running yet, starts it. |
| 1394 | """ |
| 1395 | |
| 1396 | with self: |
| 1397 | self._handler_queue.extend((what, handler) for handler in handlers) |
| 1398 | self._handlers_enqueued.notify_all() |
| 1399 | |
| 1400 | # If there is anything to handle, but there's no handler thread yet, |
| 1401 | # spin it up. This will normally happen only once, on the first call |
| 1402 | # to _enqueue_handlers(), and that thread will run all the handlers |
| 1403 | # for parsed messages. However, this can also happen is somebody calls |
| 1404 | # Request.on_response() - possibly concurrently from multiple threads - |
| 1405 | # after the channel has already been closed, and the initial handler |
| 1406 | # thread has exited. In this case, we spin up a new thread just to run |
| 1407 | # the enqueued response handlers, and it will exit as soon as it's out |
| 1408 | # of handlers to run. |
| 1409 | if len(self._handler_queue) and self._handler_thread is None: |
| 1410 | self._handler_thread = threading.Thread( |
| 1411 | target=self._run_handlers, |
| 1412 | name=f"{self} message handler", |
| 1413 | ) |
| 1414 | hide_thread_from_debugger(self._handler_thread) |
| 1415 | self._handler_thread.start() |
| 1416 | |
| 1417 | def _run_handlers(self): |
| 1418 | """Runs enqueued handlers until the channel is closed, or until the handler |
no test coverage detected