Function pyo3_asyncio::with_runtime[][src]

pub fn with_runtime<F, R>(py: Python<'_>, f: F) -> PyResult<R> where
    F: FnOnce() -> PyResult<R>, 
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 guard
  • f - The function to call in between intialization and finalization

Examples

use pyo3::prelude::*;

fn main() {
    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();
    })
}