0

I have a Python function that can be slow, so I need to be able to run that function concurrently. If I were running the Python script directly, I'd simply create multiple threads and so I would be able to easily run that function concurrently. I must use CPython, but GIL is not an issue, as my function is IO-bound (not CPU-bound).

I know I can run a Python function from Rust via libraries like PyO3 and rust-cpython. But I haven't been able to find a way to run that Python function concurrently from multiple Rust threads.

Python Subinterpreters are still experimental, AFAIK, so maybe my only option would be to somehow spawn multiple Python threads, but how do I then access them without being exclusively locked by the Rust's library GIL "wrapper"...? Is that possible at all?

yolapo
  • 19
  • 1
  • What's wrong with calling `Python::with_gil` from multiple threads? I assume that as soon as the Python code in one thread releases the GIL, the other threads will be able to acquire it and proceed. – Jmb Apr 11 '23 at 13:48

0 Answers0