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
)
| 648 | self.server_terminated = False |
| 649 | |
| 650 | def _run_callback( |
| 651 | self, callback: Callable, *args: Any, **kwargs: Any |
| 652 | ) -> "Optional[Future[Any]]": |
| 653 | """Runs the given callback with exception handling. |
| 654 | |
| 655 | If the callback is a coroutine, returns its Future. On error, aborts the |
| 656 | websocket connection and returns None. |
| 657 | """ |
| 658 | try: |
| 659 | result = callback(*args, **kwargs) |
| 660 | except Exception: |
| 661 | self.handler.log_exception(*sys.exc_info()) |
| 662 | self._abort() |
| 663 | return None |
| 664 | else: |
| 665 | if result is not None: |
| 666 | result = gen.convert_yielded(result) |
| 667 | assert self.stream is not None |
| 668 | self.stream.io_loop.add_future(result, lambda f: f.result()) |
| 669 | return result |
| 670 | |
| 671 | def on_connection_close(self) -> None: |
| 672 | self._abort() |
no test coverage detected