pub fn run<F, T>(py: Python<'_>, fut: F) -> PyResult<T>
Expand description
Run the event loop until the given Future completes
§Arguments
py
- The current PyO3 GIL guardfut
- The future to drive to completion
§Examples
fn main() {
// call this or use pyo3 0.14 "auto-initialize" feature
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
pyo3_asyncio::async_std::run(py, async move {
async_std::task::sleep(Duration::from_secs(1)).await;
Ok(())
})
.map_err(|e| {
e.print_and_set_sys_last_vars(py);
})
.unwrap();
})
}