MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / wrap_py_event_subscriber

Function wrap_py_event_subscriber

crates/python/src/py_callable.rs:849–871  ·  view source on GitHub ↗

Wrap a Python callable `(Event) -> None` for event subscribers.

(py_fn: Py<PyAny>)

Source from the content-addressed store, hash-verified

847
848/// Wrap a Python callable `(Event) -> None` for event subscribers.
849pub fn wrap_py_event_subscriber(py_fn: Py<PyAny>) -> EventSubscriberFn {
850 Arc::new(move |event: &Event| {
851 Python::attach(|py| {
852 let result = match event {
853 Event::Scope(inner) => py_fn.call1(
854 py,
855 (crate::py_types::PyScopeEvent {
856 inner: inner.clone(),
857 },),
858 ),
859 Event::Mark(inner) => py_fn.call1(
860 py,
861 (crate::py_types::PyMarkEvent {
862 inner: inner.clone(),
863 },),
864 ),
865 };
866 if let Err(e) = result {
867 eprintln!("Event subscriber error: {e}");
868 }
869 })
870 })
871}
872
873// ---------------------------------------------------------------------------
874// LLM Codec wrapper

Callers 4

register_subscriberMethod · 0.85
register_subscriberFunction · 0.85

Calls

no outgoing calls

Tested by 1