Skip to content

Speedup macOS free-threading slowest tests test_signal and test_asyncio.test_free_threading #162364

Open

Description

@cmaloney

Feature or enhancement

ARM64 MacOS M1 Refleaks NoGIL 3.x currently takes 25-49 minutes per build.

A lot of that comes from two tests currently which we can make faster with some small adjustments.

test_signal (22-27 minutes)

StressTest.test_stress_delivery_simultaneous is most of this time. The test sends a pair of signals 5000 times and waits for each pair to arrive. Since gh-93770, the wait uses support.sleeping_retry(), which sleeps at least 10 ms whenever the signals haven't arrived at the first check. The signals actually arrive within tens of microseconds, so almost all of the test's runtime is spent in those 10 ms sleeps.

We can move to the same code as test_stress_delivery_dependent which runs much faster. already waits with a 10 µs poll against an overall SHORT_TIMEOUT deadline. The proposed fix uses that same polling code (moved into a shared helper) in both tests.

This is particularly slow because the buildbot is run as a macOS background task (taskpolicy -b) which ends up causing the 10ms sleep to often stretch to 60–100 ms

test_asyncio.test_free_threading (~11 minutes)

test_unregister_lingering_tasks_of_exited_thread is a regression test added for gh-159449. With the C implementation, it takes about 12 s per run (about 0.15 s with the pure-Python one). Currently this happens a lot of times in a loop. The same bug can be caught reliably with a lot less iterations.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. self-assigned this
    on Nov 21, 2026
  2. added
    type-featureA feature request or enhancement
    testsTests in the Lib/test dir
    on Nov 21, 2026
  3. added a commit that references this issue on Nov 21, 2026
  4. added 3 commits that reference this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions