[python] Combining cudaq
module with multiprocesssing
module can result in deadlock
#1804
Open
3 of 4 tasks
Labels
bug
Something isn't working
python-lang
Anything related to the Python CUDA Quantum language implementation
runtime
CUDA quantum runtime
Required prerequisites
Describe the bug
Some applications need to use the
multiprocessing.Process
function (or theProcessPoolExecutor.run_in_executor
function) to spawn child processes to perform work. By default, Python on Linux creates the child process using the "fork" method (as described in the Python docs). The docs say the following (emphasis mine):cudaq is indeed a multithreaded process, so as it stands right now, this is problematic.
Also note that according to the docs, Python 3.14 will change this behavior.
Steps to reproduce the bug
The following example demonstrates the problem.
When running the above code with a current version of cudaq, you'll get the following results:
Note that you'll never reach the
DONE!
section. This is the bug.Expected behavior
The above example (or something very similar) should be able to run without deadlocks. As shown in the example, calling
multiprocessing.set_start_method('spawn')
ormultiprocessing.set_start_method('forkserver')
in the user program will fix the problem, but it might be nicer if this were automatically handled by the cudaq module. Any solution would need to be tested against the above example and more complicated use cases, both in regular Python and in Jupyter notebooks.Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
Suggestions listed above.
The text was updated successfully, but these errors were encountered: