python Rust互相调用 发表于 2024-01-28 更新于 2024-02-17 分类于 Rust , python , pyo3-asyncio 12345678910111213let future = Python::with_gil(|py| { // import the module containing the py_sleep function let example = py.import("example")?; // calling the py_sleep method like a normal function returns a coroutine let coroutine = example.call_method0("py_sleep")?; // convert the coroutine into a Rust future pyo3_asyncio::into_future(coroutine)})?;// await the futurefuture.await; 1234567#[pyfunction]fn call_rust_sleep(py: Python) -> PyResult<PyObject> { pyo3_asyncio::async_std::into_coroutine(py, async move { rust_sleep().await; Ok(()) })} 12345pyo3_asyncio::tokio::future_into_py(py, async move { let mut _server_handle = _server.as_ref().lock().await; _server_handle.entry_direct_hub_server(hub_name).await; Ok(())}) 本文作者: qianqians 本文链接: https://qianqians.github.io/2024/01/28/pyo3-asyncio/ 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!