monarch_with_gil_blocking

Function monarch_with_gil_blocking 

Source
pub fn monarch_with_gil_blocking<F, R>(f: F) -> R
where F: for<'py> FnOnce(Python<'py>) -> R + Send,
Expand description

Blocking wrapper around Python::with_gil for use in synchronous contexts.

Unlike monarch_with_gil, this function does NOT use the GIL_LOCK async mutex. Since it is blocking call, it simply acquires the GIL and releases it when the closure returns.

§Example

let result = monarch_with_gil_blocking(|py| {
    // Do work with Python GIL
    Ok(42)
})?;