You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This seems like another specific instance of the general issue identified in #50970.
If multiprocessing.Pool.map_async is used with maxtasksperchild and a value returned by a task is of a class not currently imported by the calling process, it can lead to a hang. Here is an example that reliably hangs for me, but which exits cleanly if ElementTree is imported at the top level.
My guess (without any further proof) is that the main process receives a pickled ElementTree and starts importing the module. Concurrently, another thread realises it needs to start a new worker, so does a fork(). The child process has a half-imported, locked ElementTree module, and tries to import it again, leading to a deadlock.
Note that this is nothing to do with ElementTree - I get the same behaviour with numpy. I chose ElementTree as a reasonably complex module (to maximise the window for the race condition) with a picklable class.
Personally I consider the fork model of multiprocessing to be dangerous and requiring of care to ensure all worker tasks are created before doing anything that can conceivably create threads, and definitely a bad combination with maxtasksperchild. So I won't shed any tears if the resolution is "won't fix, don't do that". But #50970 (comment) seems to suggest that @vstinner has some appetite for addressing such issues and hence I'm filing this.
Your environment
CPython versions tested on: 3.8.10, 3.10.4
Operating system and architecture: Ubuntu 20.04, x86_64
The text was updated successfully, but these errors were encountered:
Bug report
This seems like another specific instance of the general issue identified in #50970.
If
multiprocessing.Pool.map_async
is used withmaxtasksperchild
and a value returned by a task is of a class not currently imported by the calling process, it can lead to a hang. Here is an example that reliably hangs for me, but which exits cleanly if ElementTree is imported at the top level.Running
py-spy dump
on one of the workers shows this backtrace:My guess (without any further proof) is that the main process receives a pickled ElementTree and starts importing the module. Concurrently, another thread realises it needs to start a new worker, so does a
fork()
. The child process has a half-imported, locked ElementTree module, and tries to import it again, leading to a deadlock.Note that this is nothing to do with ElementTree - I get the same behaviour with numpy. I chose ElementTree as a reasonably complex module (to maximise the window for the race condition) with a picklable class.
Personally I consider the
fork
model ofmultiprocessing
to be dangerous and requiring of care to ensure all worker tasks are created before doing anything that can conceivably create threads, and definitely a bad combination withmaxtasksperchild
. So I won't shed any tears if the resolution is "won't fix, don't do that". But #50970 (comment) seems to suggest that @vstinner has some appetite for addressing such issues and hence I'm filing this.Your environment
The text was updated successfully, but these errors were encountered: