Title: test_threading: EventTests.test_set_and_clear times out on a busy machine · Issue #158336 · python/cpython · GitHub
Open Graph Title: test_threading: EventTests.test_set_and_clear times out on a busy machine · Issue #158336 · python/cpython
X Title: test_threading: EventTests.test_set_and_clear times out on a busy machine · Issue #158336 · python/cpython
Description: test_set_and_clear in Lib/test/lock_tests.py starts five threads that call event.wait(), sleeps for 50 ms (wait_threads_blocked()), and then calls event.set() and event.clear(). If a thread only reaches wait() after clear(), it sees the ...
Open Graph Description: test_set_and_clear in Lib/test/lock_tests.py starts five threads that call event.wait(), sleeps for 50 ms (wait_threads_blocked()), and then calls event.set() and event.clear(). If a thread only re...
X Description: test_set_and_clear in Lib/test/lock_tests.py starts five threads that call event.wait(), sleeps for 50 ms (wait_threads_blocked()), and then calls event.set() and event.clear(). If a thread only re...
Opengraph URL: https://github.com/python/cpython/issues/158336
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_threading: EventTests.test_set_and_clear times out on a busy machine","articleBody":"`test_set_and_clear` in `Lib/test/lock_tests.py` starts five threads that call `event.wait()`, sleeps for 50 ms (`wait_threads_blocked()`), and then calls `event.set()` and `event.clear()`. If a thread only reaches `wait()` after `clear()`, it sees the flag unset and waits for `LONG_TIMEOUT`, so `Bunch.__exit__` gives up after `SHORT_TIMEOUT`:\n\n```\nFAIL: test_set_and_clear (test.test_threading.EventTests.test_set_and_clear)\nTraceback (most recent call last):\n File \"Lib/test/lock_tests.py\", line 574, in test_set_and_clear\n with Bunch(f, N):\n File \"Lib/test/lock_tests.py\", line 77, in __exit__\n for _ in support.sleeping_retry(support.SHORT_TIMEOUT):\n ...\nAssertionError: timeout (30.3 seconds)\n```\n\nThis happened in the TSan (free-threading) job of an unrelated PR, gh-158286: https://github.com/python/cpython/actions/runs/36356561195/job/108725383176\n\nIt reproduces on a free-threaded debug build with TSan (`--with-thread-sanitizer --with-pydebug --disable-gil`) when the test shares two CPUs with four busy-looping processes:\n\n```\nfor i in 1 2 3 4; do taskset --cpu-list 12-13 python3 -c \"while True: pass\" & done\ntaskset --cpu-list 12-13 ./python -m test test_threading --match test_set_and_clear\n```\n\nThe test failed in 9 of 40 runs. In a copy of the test that counts `event._cond._waiters` just before `set()`, every failure had a thread that had not yet started waiting; none was a lost wakeup.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158337\n* gh-161682\n* gh-161683\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/matthiasgoergens","@type":"Person","name":"matthiasgoergens"},"datePublished":"2026-09-28T11:39:45Z","url":"https://github.com/python/cpython/issues/158336"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e19f0f4e-fde9-4914-32b9-9186d80adedd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF32:23E48:ABABC8:D703D9:6B0231AF |
| html-safe-nonce | 106a1f6f5df3f699cc99b1ab36c54299e2eaaa836009ff7b27ea6df4b2313efc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjMyOjIzRTQ4OkFCQUJDODpENzAzRDk6NkIwMjMxQUYiLCJ2aXNpdG9yX2lkIjoiNzgyNDM0ODQ2NTYwMDgwMzI0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc8c769d77d566e81f0ff9b31dc9dffb0fd0fc5e425718d2868c8e8a1a87b2e9 |
| hovercard-subject-tag | issue:5613916840 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158336/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0de7cfc260b0c4e673996e7fd7b27b9c90a6eb52f6066c0d8a0a8bc79c9fa667/python/cpython/issues/158336 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0de7cfc260b0c4e673996e7fd7b27b9c90a6eb52f6066c0d8a0a8bc79c9fa667/python/cpython/issues/158336 |
| og:image:alt | test_set_and_clear in Lib/test/lock_tests.py starts five threads that call event.wait(), sleeps for 50 ms (wait_threads_blocked()), and then calls event.set() and event.clear(). If a thread only re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | matthiasgoergens |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width