]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.15] gh-119592: gh-152967: Fix ProcessPoolExecutor stranding submitted work when...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 8 Jul 2026 22:43:48 +0000 (00:43 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Jul 2026 22:43:48 +0000 (15:43 -0700)
commitcbbccf37b2be14fca026e087587b9611da371cbc
treedc44a369e530af0dc52069c3d0bd899b5b9d44eb
parentc5e73f8c91dd7a6aa7587b60e526b3e3a915bb3b
[3.15] gh-119592: gh-152967: Fix ProcessPoolExecutor stranding submitted work when a max_tasks_per_child worker exits (GH-152978) (#153363)

gh-119592: gh-152967: Fix ProcessPoolExecutor stranding submitted work when a max_tasks_per_child worker exits (GH-152978)

gh-119592: Fix ProcessPoolExecutor stranding submitted work when a max_tasks_per_child worker exits

Worker replacement went through the executor object: the manager thread
read executor attributes that shutdown(wait=False) clears concurrently,
and could not replace workers at all once the executor was garbage
collected. A worker exiting at its max_tasks_per_child limit in those
states left the remaining submitted work permanently unexecuted and hung
interpreter exit; the racing case could crash the manager thread.

Replace workers from the executor manager thread using its own state
plus configuration read through the live executor weakref, which
shutdown() never clears:

- After shutdown(wait=False) with the executor still referenced, a
  replacement is spawned and the remaining work is executed as
  documented.
- Once the executor has been garbage collected (gh-152967), or a
  replacement worker cannot be started and no workers remain, the
  remaining futures now fail with BrokenProcessPool instead of never
  resolving.
- A new _force_shutting_down flag stops both spawn paths from starting
  workers that would escape terminate_workers()/kill_workers().
(cherry picked from commit 0c6422ff6a13ae309493fb7a358cb35d7ea959c8)

Reviewed-multiple-times-by: Gregory P. Smith
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Lib/concurrent/futures/process.py
Lib/test/test_concurrent_futures/test_process_pool.py
Misc/NEWS.d/next/Library/2026-07-03-18-30-00.gh-issue-119592.mQr3Vx.rst [new file with mode: 0644]