Skip to content

Fix flaky test_interrupt_stops_workers on Python 3.10 - #567

Merged
gmloose merged 1 commit into
masterfrom
fix-flaky-interrupt-test
Nov 9, 2026
Merged

gmloose merged 1 commit into
masterfrom
fix-flaky-interrupt-test

Conversation

@gmloose

@gmloose gmloose commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Problem

On Python 3.10, test_interrupt_stops_workers in test/tmulti_proc.py fails intermittently with "workers still running". Locally it failed in 8 of 20 runs (with master's multi_proc.py). The wheel builds run this test on cp310.

Cause

After the interrupt, parallel_map terminates and joins its workers, and the executor's manager thread joins the same workers (join_executor_internals in concurrent.futures.process). Only one of the two threads gets the exit status from the OS (waitpid). The other gets ECHILD, which Popen.poll() turns into "no exit code yet", so its join() returns without an exit code.

If the manager thread wins, the worker has exited and been reaped, but multiprocessing.active_children() still lists it until the manager thread has stored the exit code. Instrumenting _terminate_workers showed exactly this: after its join() calls, one worker had exit code None, and a moment later active_children() was empty.

The delay is at most about 1 ms (measured over 30 runs). The test checked active_children() immediately after parallel_map returned, so it sometimes failed. The race exists in other Python versions too, but the timing made it show up on 3.10.

Fix

parallel_map behaves correctly: when it re-raises, all workers have been terminated and have exited. Only the test changes: it waits for active_children() to become empty, for at most 5 s, before asserting. That's far more than the ~1 ms delay, and much less than the 60-second tasks, so a worker that is really still running still fails the test.

Testing

  • With the fix, Python 3.10.20: 0 failures in 60 repetitions of the test (before: 8 failures in 20).
  • tmulti_proc.py passes on Python 3.10, 3.11, 3.12, 3.13 and 3.14.

This is independent of #566 (the fork deadlock in test_overlapping_calls); both PRs change different parts of tmulti_proc.py.

🤖 Generated with Claude Code

After an interrupt, parallel_map terminates and joins the workers, but the
executor's manager thread may join them at the same time. Only one of the
two gets the exit status from the OS; if it's the manager thread, the
worker has exited and been reaped, but multiprocessing.active_children()
still lists it until the manager thread has recorded its exit code (at
most ~1 ms later). The test checked immediately, and failed in about 1 of
3 runs on Python 3.10. Allow a short delay (at most 5 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gmloose gmloose self-assigned this Nov 7, 2026
@gmloose
gmloose requested a review from darafferty November 7, 2026 00:39
@gmloose

gmloose commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T00:45:21.106554Z 3ffc72f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 3ffc72fff2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@darafferty darafferty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@gmloose
gmloose merged commit 87a2e5b into master Nov 9, 2026
1 check passed
gmloose added a commit that referenced this pull request Nov 9, 2026
After an interrupt, parallel_map terminates and joins the workers, but the
executor's manager thread may join them at the same time. Only one of the
two gets the exit status from the OS; if it's the manager thread, the
worker has exited and been reaped, but multiprocessing.active_children()
still lists it until the manager thread has recorded its exit code (at
most ~1 ms later). The test checked immediately, and failed in about 1 of
3 runs on Python 3.10. Allow a short delay (at most 5 s).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@gmloose
gmloose deleted the fix-flaky-interrupt-test branch November 9, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants