MCPcopy
hub / github.com/Textualize/textual / invoke

Function invoke

src/textual/_callback.py:62–96  ·  view source on GitHub ↗

Invoke a callback with an arbitrary number of parameters. Args: callback: The callable to be invoked. Returns: The return value of the invoked callable.

(callback: Callable[..., Any], *params: object)

Source from the content-addressed store, hash-verified

60
61
62async def invoke(callback: Callable[..., Any], *params: object) -> Any:
63 """Invoke a callback with an arbitrary number of parameters.
64
65 Args:
66 callback: The callable to be invoked.
67
68 Returns:
69 The return value of the invoked callable.
70 """
71
72 app: App | None
73 try:
74 app = active_app.get()
75 except LookupError:
76 # May occur if this method is called outside of an app context (i.e. in a unit test)
77 app = None
78
79 if app is not None and "debug" in app.features:
80 # In debug mode we will warn about callbacks that may be stuck
81 def log_slow() -> None:
82 """Log a message regarding a slow callback."""
83 assert app is not None
84 app.log.warning(
85 f"Callback {callback} is still pending after {INVOKE_TIMEOUT_WARNING} seconds"
86 )
87
88 call_later_handle = asyncio.get_running_loop().call_later(
89 INVOKE_TIMEOUT_WARNING, log_slow
90 )
91 try:
92 return await _invoke(callback, *params)
93 finally:
94 call_later_handle.cancel()
95 else:
96 return await _invoke(callback, *params)

Callers 14

dispatch_keyFunction · 0.90
await_pruneMethod · 0.90
_tickMethod · 0.90
on_changeMethod · 0.90
run_callbackMethod · 0.90
_dispatch_actionMethod · 0.90
invoke_callbackMethod · 0.90
_flush_next_callbacksMethod · 0.90
_on_messageMethod · 0.90

Calls 4

_invokeFunction · 0.85
call_laterMethod · 0.80
cancelMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…