Closed JohnScience closed 1 year ago
This is unintuitive, but documented behavior because the conversion itself needs to call asyncio.get_running_loop()
. See this section for a more detailed explanation: https://github.com/awestlake87/pyo3-asyncio#a-note-about-asynciorun
You need to wrap your hello
function in a Python coroutine to get it to work since the running loop is not available until you're inside the asyncio.run(...)
context.
from pyo3_async_hello import hello
import asyncio
async def main():
return await hello()
asyncio.run(main())
@awestlake87 What a blunder from me, thank you!
🐛 Bug Reports
Note:
conda activate
->maturin dev
-> ... didn't help either🌍 Environment
Your operating system and version:
Your python version:
How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: Installed from the official website
Your Rust version (
rustc --version
):rustc 1.72.1 (d5c2e9c34 2023-09-13)
Your PyO3 version:
0.19.0
Have you tried using latest PyO3 master (replace
version = "0.x.y"
withgit = "https://github.com/awestlake87/pyo3-asyncio")?
: Yes, it didn't help💥 Reproducing
Please provide a minimal working example. This means both the Rust code and the Python.
src/lib.rs
:Python code:
MWE: https://github.com/JohnScience/pyo3_async_hello
Please also write what exact flags are required to reproduce your results.