this post was submitted on 08 Apr 2024
20 points (100.0% liked)

Rust

5989 readers
21 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Hello,

I am trying to wrap some Rust code that uses sea-orm compiled with "runtime-tokio-rustls" feature. I am using the new pyo3 "experimental-async" feature, which AFAIK is based on pyo3_async.

So I get that this is supposed to be runtime-agnostic, and not have two event loops, one for python async and one for rust async.

But, how do I tell pyo3 to use tokio runtime specifically? Or, how do I set up Python asyncio eventloop to use tokio somehow?

Indeed, it seems that it does not use tokio runtime, so I get this error when I invoke the rust async function from Python:

pyo3_runtime.PanicException: this functionality requires a Tokio context
you are viewing a single comment's thread
view the rest of the comments
[–] BatmanAoD@programming.dev 3 points 7 months ago

I'm not familiar with pyo3_async, but I don't think you can force Python asyncio to use the Tokio event loop. This is discussed in the documentation of a different PyO3 async crate, pyo3-asyblncio: https://docs.rs/pyo3-asyncio/latest/pyo3_asyncio/#why-two-event-loops