concurrent.futures.ProcessPoolExecutor raises during shutdown #131598
Labels
stdlib
Python modules in the Lib dir
topic-multiprocessing
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
ProcessPoolExecutor
invokes future done callbacks from its manager thread. When one of those future callbacks invokesProcessPoolExecutor.shutdown()
, shut down fails with aRuntimeError: cannot join current thread
because the implementation joins the manager thread without protecting against self-joins.The relevant lines
Lib/concurrent/futures/process.py:845-846
currently read:but should probably be updated to:
Invoking
shutdown(False)
avoids the problem but also makes it impossible to wait for pool completion. A more general solution would be to deprecate thewait
parameter forshutdown
, never waiting in that method, and add a separate method, saywait_for_shutdown
, that uses athreading.Event
to wake any waiting threads. Alas, correctly setting thatEvent
is going to be a bit involved.While I tested on 3.12, the bug is also present in 3.13 and current.
CPython versions tested on:
3.12
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: