Skip to content

gh-101267: [bug] ProcessPoolExecutor should not share one BrokenProcessPool exception among all failed futures#101268

Merged
gpshead merged 6 commits into
python:mainfrom
daniel-shields:fix-101267
Jun 13, 2026
Merged

gh-101267: [bug] ProcessPoolExecutor should not share one BrokenProcessPool exception among all failed futures#101268
gpshead merged 6 commits into
python:mainfrom
daniel-shields:fix-101267

Conversation

@daniel-shields

@daniel-shields daniel-shields commented Jan 23, 2023

Copy link
Copy Markdown
Contributor

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost

ghost commented Jan 23, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@daniel-shields daniel-shields changed the title gh-101267: ProcessPoolExecutor should not share one BrokenProcessPool exception among all failed futures gh-101267: [bug] ProcessPoolExecutor should not share one BrokenProcessPool exception among all failed futures Jan 23, 2023
@daniel-shields

Copy link
Copy Markdown
Contributor Author

Could you please take a look @gpshead?

@arhadthedev arhadthedev added stdlib Standard Library Python modules in the Lib/ directory topic-multiprocessing labels Feb 25, 2023
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

1 similar comment
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2026
gpshead added 4 commits June 13, 2026 06:22
Adapt the pythongh-101267 fix to the current code shape:

* concurrent.futures.process.ProcessPoolExecutor._terminate_broken()
  was refactored (renamed from terminate_broken(), and gained the
  exit-code reporting from pythongh-139462).  Reapply the fix on top: compute
  the broken-pool cause once, then create a fresh BrokenProcessPool
  exception per pending future inside the loop.  Preserve the
  InvalidStateError guard around set_exception().

* Lib/test/test_concurrent_futures.py was split into a package.  Move
  the new regression test into test_concurrent_futures/test_process_pool.py.
…ting

Two refinements to the broken-pool handling:

* submit() raises BrokenProcessPool(self._broken) so the message says why
  the pool broke, rather than a generic fixed string.
* Build the cause traceback string once before the per-future loop instead
  of rebuilding the same f-string on every iteration.
…king

* Block the workers on a never-set Event (via the harness create_event())
  instead of submitting time.sleep(3): the sleep could finish before the
  worker is terminated on a loaded machine, completing the future and
  raising no BrokenProcessPool.
* Use try/except/else with self.fail() rather than seeding count = None,
  so a missing exception is reported clearly. assertRaises() can't be used
  here because it strips the traceback the test needs to inspect.
Describe the actual failure (re-raising one shared exception appends a
traceback to it on each Future.result()) and cross-reference the API names.
@gpshead gpshead self-assigned this Jun 13, 2026
@gpshead gpshead added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes and removed needs backport to 3.13 bugs and security fixes labels Jun 13, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 13, 2026
@gpshead gpshead merged commit 3c00ebc into python:main Jun 13, 2026
63 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @daniel-shields for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @daniel-shields and @gpshead, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3c00ebc2bbd902495b163def850bc931420209fc 3.14

@bedevere-app

bedevere-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

GH-151430 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 13, 2026
gpshead added a commit to miss-islington/cpython that referenced this pull request Jun 13, 2026
…Pool exception among all failed futures (pythonGH-101268)

(cherry picked from commit 3c00ebc)

Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
gpshead added a commit to miss-islington/cpython that referenced this pull request Jun 13, 2026
…Pool exception among all failed futures (pythonGH-101268)

(cherry picked from commit 3c00ebc)

Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
@gpshead gpshead removed the needs backport to 3.14 bugs and security fixes label Jun 13, 2026
@bedevere-app

bedevere-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

GH-151431 is a backport of this pull request to the 3.14 branch.

gpshead added a commit that referenced this pull request Jun 13, 2026
…sPool exception among all failed futures (GH-101268) (#151430)

gh-101267: ProcessPoolExecutor no longer shares 1 BrokenProcessPool exception among all failed futures (GH-101268)
(cherry picked from commit 3c00ebc)

Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
gpshead added a commit that referenced this pull request Jun 13, 2026
…sPool exception among all failed futures (GH-101268) (#151431)

* gh-101267: ProcessPoolExecutor no longer shares 1 BrokenProcessPool exception among all failed futures (GH-101268)
(cherry picked from commit 3c00ebc)

Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
(cherry picked from commit 4e8c9c6)

* Drop the abrupt-exit-code reporting from the 3.14 backport

Reporting the exit codes of processes that died without a known cause
is a new feature, not part of the gh-101267 bugfix. Keep only the
bugfix on 3.14: each failed future gets its own BrokenProcessPool
exception instead of one shared instance.

---------

Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
gpshead added a commit that referenced this pull request Jun 13, 2026
…sPool exception among all failed futures (GH-101268) (GH-151431) (#151435)

[3.14] gh-101267: ProcessPoolExecutor no longer shares 1 BrokenProcessPool exception among all failed futures (GH-101268) (GH-151431)

* gh-101267: ProcessPoolExecutor no longer shares 1 BrokenProcessPool exception among all failed futures (GH-101268)
(cherry picked from commit 3c00ebc)




(cherry picked from commit 4e8c9c6)

* Drop the abrupt-exit-code reporting from the 3.14 backport

Reporting the exit codes of processes that died without a known cause
is a new feature, not part of the gh-101267 bugfix. Keep only the
bugfix on 3.14: each failed future gets its own BrokenProcessPool
exception instead of one shared instance.

---------
(cherry picked from commit 27ff2c8)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Daniel Shields <daniel.shields@twosigma.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stdlib Standard Library Python modules in the Lib/ directory topic-multiprocessing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants