Runs the given callback with exception handling. If the callback is a coroutine, returns its Future. On error, aborts the websocket connection and returns None.
(
self, callback: Callable, *args: Any, **kwargs: Any
)
| 624 | self.server_terminated = False |
| 625 | |
| 626 | def _run_callback( |
| 627 | self, callback: Callable, *args: Any, **kwargs: Any |
| 628 | ) -> "Optional[Future[Any]]": |
| 629 | """Runs the given callback with exception handling. |
| 630 | |
| 631 | If the callback is a coroutine, returns its Future. On error, aborts the |
| 632 | websocket connection and returns None. |
| 633 | """ |
| 634 | try: |
| 635 | result = callback(*args, **kwargs) |
| 636 | except Exception: |
| 637 | self.handler.log_exception(*sys.exc_info()) |
| 638 | self._abort() |
| 639 | return None |
| 640 | else: |
| 641 | if result is not None: |
| 642 | result = gen.convert_yielded(result) |
| 643 | assert self.stream is not None |
| 644 | self.stream.io_loop.add_future(result, lambda f: f.result()) |
| 645 | return result |
| 646 | |
| 647 | def on_connection_close(self) -> None: |
| 648 | self._abort() |
no test coverage detected