Skip to content

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Sep 21, 2025

In GH-139158, I added a test that sent KeyboardInterrupt to the main thread so it would interrupt _Py_Finalize and shut down. There was a subtle race condition there:

  1. The main thread starts the subthread by calling _thread._start_joinable_thread.
  2. The thread is physically created before _start_joinable_thread finishes from Python's perspective, so it begins execution.
  3. The subthread prints out a, signaling to the parent process that it is ready and may send the interrupt signal.
  4. The subthread yields the GIL anywhere after this point.
  5. The main thread acquires the GIL, and then finishes executing _start_joinable_thread.
  6. The parent process sends the KeyboardInterrupt before _Py_Finalize is reached. Python returns -2, which fails the test.

The simplest way to fix this is by allowing a return code of -2 (-SIGINT) in addition to 0.

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit 2a28762 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F139219%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@encukou
Copy link
Member

encukou commented Sep 23, 2025

The buildbot failures are unrelated, pre-existing issues.

@encukou encukou merged commit 6b4e3fe into python:main Sep 23, 2025
113 of 127 checks passed
@encukou
Copy link
Member

encukou commented Sep 23, 2025

Thank you!

@ZeroIntensity ZeroIntensity deleted the fix-failures branch September 23, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants