Repository navigation
Conversation
A task raising a BaseException which is not an Exception, such as SystemExit from exit() or a SIGTERM handler, ended the worker before the result of the job was sent, so that the pool hung forever. The exception is now sent back and raised by AsyncResult.get(), like other exceptions. A worker process then exits as before and is replaced. A ThreadPool thread keeps running instead, since an exited thread is only replaced when the worker handler happens to wake up.
9 of 13 tasks
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.
A task raising a
BaseExceptionthat isn't anException, such asSystemExitfromexit()or a SIGTERM handler, ended the pool worker before the job's result was sent, somap()/AsyncResult.get()waited forever. See the analysis in the issue.The worker now catches
BaseExceptionand sends it back like any other exception. In a worker process it is then re-raised after the result is sent, so the worker exits with the same exit code and is replaced, as before. Keeping the worker alive instead (asProcessPoolExecutordoes) would makePool.terminate()hang on a busy worker whose SIGTERM handler raisesSystemExit.ThreadPoolthreads report the exception and keep running, since an exited thread is only replaced when the worker handler happens to wake up.Behavior changes callers will see:
get(),map(),imap()etc. now raise the task'sSystemExit/KeyboardInterrupt/ otherBaseExceptioninstead of hanging, likeFuture.result()inconcurrent.futures. Left uncaught in the main thread, it exits the parent with that code.error_callbackis called with it.ThreadPooltask that callssys.exit()no longer ends its thread.Known limitation: for a pool created through a
Manager, the manager's server only catchesExceptionaround proxied calls (Server.serve_client), soget()on such a job now ends that client's connection (EOFError) instead of timing out. Fixing that means changingmanagers.py, so I've left it out to keep this PR focused, and I'm happy to follow up separately. Workers that die without raising (os._exit(), a segfault, SIGKILL) aren't covered either; that's gh-66587.Tests cover
apply_async()and the issue'smap()reproducer for process and thread pools, and check that a worker process (including one started by the worker handler thread) still exits with the task's exit code and is replaced. On the current code they fail with a timeout rather than hanging.test_multiprocessing_fork,_spawn,_forkserver,_main_handlingandtest_concurrent_futurespass locally on Linux with--fail-env-changed, and the new tests are clean under-R 3:3. I also ran a set of scenarios against main and this branch under all three start methods (every Pool API,KeyboardInterrupt/GeneratorExit/ customBaseException, unpicklable exit codes,maxtasksperchild,buffersize,terminate()with a SIGTERM handler, real Ctrl-C, pools used from a non-main thread) and found no new hangs or crashes.