chitralverma commented on PR #6622: URL: https://github.com/apache/opendal/pull/6622#issuecomment-3405484574
> Can we? 1. the snippet that you shared **does not work**. it fails with: ``` pyo3_runtime.PanicException: there is no reactor running, must be called from the context of a Tokio 1.x runtime ``` 2. [This example](https://pyo3.rs/v0.26.0/async-await#using-async-and-await) from pyo3 docs **works but doesn't use tokio.** Same thing you mentioned in [one of the comments](https://github.com/apache/opendal/pull/6622#issuecomment-3402480100). 3. I managed to merge the two and the **following works with tokio**. This is because i inject the tokio runtime that was being internally used in the existing implementation ```rust #[pyo3(signature=(seconds, result=None))] async fn sleep(&self, seconds: f64, result: Option<Py<PyAny>>) -> Option<Py<PyAny>> { let (tx, rx) = tokio::sync::oneshot::channel(); let rt = pyo3_async_runtimes::tokio::get_runtime(); // <- tokio runtime injected let handle = rt.handle().clone(); // <- injected runtime used to create a cheap handle handle.spawn(async move { tokio::time::sleep(tokio::time::Duration::from_secs_f64(seconds)).await; let _ = tx.send(result); }); rx.await.unwrap() } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
