python Rust互相调用

1
2
3
4
5
6
7
8
9
10
11
12
13
let 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 future
future.await;
1
2
3
4
5
6
7
#[pyfunction]
fn call_rust_sleep(py: Python) -> PyResult<PyObject> {
pyo3_asyncio::async_std::into_coroutine(py, async move {
rust_sleep().await;
Ok(())
})
}
1
2
3
4
5
pyo3_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(())
})