Function pyo3_asyncio::with_runtime [−][src]
pub fn with_runtime<F, R>(py: Python<'_>, f: F) -> PyResult<R> where
F: FnOnce() -> PyResult<R>,
👎 Deprecated since 0.14.0:
Use the pyo3_asyncio::async_std::run or pyo3_asyncio::tokio::run instead (see the migration guide for more details)
Expand description
Wraps the provided function with the initialization and finalization for PyO3 Asyncio
This function MUST be called from the main thread.
Arguments
py
- The current PyO3 GIL guardf
- The function to call in between intialization and finalization
Examples
use pyo3::prelude::*; fn main() { // Call this function or use pyo3's "auto-initialize" feature pyo3::prepare_freethreaded_python(); Python::with_gil(|py| { pyo3_asyncio::with_runtime(py, || { println!("PyO3 Asyncio Initialized!"); Ok(()) }) .map_err(|e| { e.print_and_set_sys_last_vars(py); }) .unwrap(); }) }