Function pyo3_asyncio::run_forever [−][src]
pub fn run_forever(py: Python<'_>) -> PyResult<()>
Run the event loop forever
This can be called instead of run_until_complete
to run the event loop
until stop
is called rather than driving a future to completion.
After this function returns, the event loop can be resumed with either run_until_complete
or
crate::run_forever
Arguments
py
- The current PyO3 GIL guard
Examples
// Wait 1 second, then stop the event loop async_std::task::spawn(async move { async_std::task::sleep(Duration::from_secs(1)).await; Python::with_gil(|py| { let event_loop = pyo3_asyncio::get_event_loop(py); event_loop .call_method1( "call_soon_threadsafe", (event_loop .getattr("stop") .map_err(|e| e.print_and_set_sys_last_vars(py)) .unwrap(),), ) .map_err(|e| e.print_and_set_sys_last_vars(py)) .unwrap(); }) }); // block until stop is called pyo3_asyncio::run_forever(py)?;