Skip to content

tests: raise the test_gil_scoped timeout on Windows free-threaded - #6321

Merged
rwgk merged 1 commit into
pybind:masterfrom
henryiii:tests/gil-scoped-win-ft-timeout
Nov 27, 2026
Merged

rwgk merged 1 commit into
pybind:masterfrom
henryiii:tests/gil-scoped-win-ft-timeout

Conversation

@henryiii

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

The rare test_gil_scoped.py "DEADLOCK" failure on windows-latest, 3.14t (logging added in #6293) is not a deadlock. The child process is slow, not blocked.

On free-threaded CPython, a blocking acquire of a held PyMutex calls _Py_yield() (SwitchToThread() on Windows) up to 40 times before it parks (_PyMutex_LockTimed in Python/lock.c). Thread.start() waits on such a lock. When other processes use the CPU, each start takes about 0.35 s on a GitHub Windows runner, where a GIL build takes about 0.03 s. In CI, the CMake build that runs in parallel with pytest supplies the load. Native stacks from a stress job show the main thread in _Py_yield from _PyMutex_LockTimed, with the GIL disabled and no stop-the-world request.

This PR raises the default subprocess timeout from 10 s to 60 s on Windows free-threaded builds only.

Results from a stress job on a Windows runner with four busy processes, sequential 8-thread cases:

Timeout Runs False deadlocks
10 s 33 11
60 s 196 0

Without the busy processes, there were 0 failures in 538,000 runs with the 10 s timeout.

On free-threaded CPython, a blocking acquire of a held PyMutex calls
SwitchToThread() up to 40 times before it parks. When other processes
use the CPU, each Thread.start() can take seconds, and the 10 s
subprocess timeout reported a deadlock that did not exist.

Assisted-by: ClaudeCode:claude-fable-5-2

@rwgk rwgk 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.

codex: no findings

@rwgk
rwgk merged commit 5a93580 into pybind:master Nov 27, 2026
94 checks passed
@rwgk
rwgk deleted the tests/gil-scoped-win-ft-timeout branch November 27, 2026 07:29
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants