MCPcopy
hub / github.com/tornadoweb/tornado / _run_callback

Method _run_callback

tornado/websocket.py:650–669  ·  view source on GitHub ↗

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
    )

Source from the content-addressed store, hash-verified

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()

Callers 1

_handle_messageMethod · 0.45

Calls 5

_abortMethod · 0.95
add_futureMethod · 0.80
resultMethod · 0.80
callbackFunction · 0.70
log_exceptionMethod · 0.45

Tested by

no test coverage detected