Repository navigation
Conversation
ProcessPoolExecutor runs Future done callbacks on the executor manager
thread. Calling shutdown(wait=True) from such a callback tried to join
that same thread and raised RuntimeError("cannot join current thread").
Skip the join and leave the manager's queues intact so it can finish
any remaining work and clean up after the callback returns.
Fixes python#131598
Assisted-by: Grok Bot
ProcessPoolExecutor.shutdown is not a documented Sphinx target; point at Executor.shutdown and the ProcessPoolExecutor class instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ProcessPoolExecutorrunsFuturedone callbacks on the executor manager thread. Callingshutdown(wait=True)from such a callback tried tojoin()that same thread and raisedRuntimeError("cannot join current thread").YvesDup wondered in the issue whether gh-136655 / #140021 already fixed this. They did not: on current main the repro still fails at the
self._executor_manager_thread.join()inProcessPoolExecutor.shutdown.This change:
shutdown(wait=True)is invoked from the manager thread itselfA try/except around
join()alone is not enough. Afterjoin()the method closes_result_queueand drops the queue/process references. Doing that while the manager thread is still inside the callback breaks other pending futures (OSError: handle is closed).Regression tests cover all three start methods (
fork,forkserver,spawn):Fixes #131598
I reproduced the
RuntimeErroron current main, added the failing tests first, then applied the fix../python -m test test_concurrent_futures.test_shutdown test_concurrent_futures.test_deadlock test_concurrent_futures.test_process_pool— 248 tests, 17 skipped, OK.AI assistance: I used an AI coding agent to reproduce the bug, draft the fix and tests, and run the test suite. I reviewed the shutdown path against the manager-thread loop so queues are not torn down while the manager still needs them.