Skip to content

test_interrupt flaky in free-threading interpreters - #12730

Merged
crusaderky merged 3 commits into
dask:mainfrom
crusaderky:ft-flaky
Nov 13, 2026
Merged

crusaderky merged 3 commits into
dask:mainfrom
crusaderky:ft-flaky

Conversation

@crusaderky

@crusaderky crusaderky commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

#12437 identified test_interrupt[True] to be flaky in Python 3.14t due to python/cpython#150873
test_interrupt[False] also hangs in free-threading interpreters due to python/cpython#148874

@github-actions

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     29 files  ±0       29 suites  ±0   6h 9m 53s ⏱️ - 30m 24s
 19 929 tests ±0   18 500 ✅ ±0   1 429 💤 ±0  0 ❌ ±0 
436 258 runs  ±0  384 803 ✅ +2  51 455 💤  - 2  0 ❌ ±0 

Results for commit 4d70ca9. ± Comparison against base commit 025d6ac.

`test_threaded.py::test_interrupt` flakes on free-threaded CPython: the test
hangs for the full pytest-timeout budget inside
`ThreadPoolExecutor.__exit__` -> `shutdown(wait=True)` -> `Thread.join()`.

Root cause is python/cpython#148874 (still open, and
labelled for both 3.14 and 3.15): since 3.14 `with X:` compiles to
`LOAD_SPECIAL __enter__; CALL`, and `CALL` ends with `_CHECK_PERIODIC_AT_END`,
which runs signal handlers.  If the handler raises, `frame->instr_ptr` still
points at `CALL`, i.e. at an offset that the with-statement's exception table
does not cover, so `__exit__` never runs and whatever `__enter__` acquired is
leaked forever - a `threading.Lock`, a `queue.Queue` mutex, or
`concurrent.futures.Future._condition`.

Free-threaded builds run the eval breaker far more eagerly than GIL ones, so a
single Ctrl+C has a realistic chance of landing in that window.  When it does,
a worker thread ends up blocked forever on the leaked lock, and joining it in
`shutdown()` wedges the whole pytest session.  Reproduced locally (~1 leaked
lock per 1700 signalled `with lock:` acquisitions on 3.14t, hangs within a few
hundred to a few thousand iterations of the previous test body on both 3.14t
and 3.15t).

Dask cannot fix this: the leaked locks belong to `concurrent.futures` and to
the interpreter.  Move the workload to a subprocess so that a leaked lock can
only take down the child, and exit the child with `os._exit()` so that its
cleanup cannot hang either.  The test still asserts that `get()` raises
`KeyboardInterrupt` instead of waiting for the running tasks.
@crusaderky crusaderky changed the title [unsupervised AI] Run test_interrupt in a subprocess test_interrupt flaky in free-threading interpreters Nov 13, 2026
@crusaderky crusaderky changed the title test_interrupt flaky in free-threading interpreters test_interrupt flaky in free-threading interpreters Nov 13, 2026
@crusaderky
crusaderky marked this pull request as ready for review November 13, 2026 16:15
@crusaderky
crusaderky merged commit 249a51a into dask:main Nov 13, 2026
35 of 37 checks passed
@crusaderky
crusaderky deleted the ft-flaky branch November 13, 2026 16:56
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.

1 participant