Replies: 1 comment 1 reply
-
You are already holding the gil because it is called from python. You can acquire the gil on the current thread again, because it is re-entrant, but not on another thread, where it will block (and deadlock, in this case). You can get around this with https://docs.rs/pyo3/latest/pyo3/marker/struct.Python.html#method.allow_threads
Are you sure you actually want to use tokio? You haven't gone into depth on what you are doing but based on this it does not seem appropriate for your tasks. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First off, thanks for PyO3. It works amazingly well, and I love having the ability to write Python libraries (like VegaFusion) in Rust!
Now for the question. I've run into a deadlock that I don't think is the same kind of situation as https://pyo3.rs/v0.15.1/faq.html#im-experiencing-deadlocks-using-pyo3-with-lazy_static-or-once_cell. The deadlock happens when attempting to acquire the GIL from inside a
tokio::spawn
async block, and only when tokio is running in multi-threaded mode.Here's a repro:
cargo.toml
lib.rs
try_it.py
So, everything works fine for the current thread tokio runtime, but the deadlock happens for the mult-threaded case.
I can use the single threaded runtime for now, and I realize that using the multi-threaded runtime won't speed up the Python code due to the GIL. But, I'd like to use the multi-threaded runtime because, in VegaFusion, I have other tasks that don't require the GIL that I'd like to be able to parallelize.
I'd appreciate any tips or ideas folks have. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions