Title: Potential thread unsafety in test_free_threading.test_monitoring · Issue #135633 · python/cpython · GitHub
Open Graph Title: Potential thread unsafety in test_free_threading.test_monitoring · Issue #135633 · python/cpython
X Title: Potential thread unsafety in test_free_threading.test_monitoring · Issue #135633 · python/cpython
Description: Bug report Bug description: It seems that there is some kind of race with test_free_threading.test_monitoring, specifically the sys.settrace tests: cpython/Lib/test/test_free_threading/test_monitoring.py Lines 143 to 166 in fba5dde @thre...
Open Graph Description: Bug report Bug description: It seems that there is some kind of race with test_free_threading.test_monitoring, specifically the sys.settrace tests: cpython/Lib/test/test_free_threading/test_monitor...
X Description: Bug report Bug description: It seems that there is some kind of race with test_free_threading.test_monitoring, specifically the sys.settrace tests: cpython/Lib/test/test_free_threading/test_monitor...
Opengraph URL: https://github.com/python/cpython/issues/135633
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Potential thread unsafety in test_free_threading.test_monitoring","articleBody":"# Bug report\n\n### Bug description:\n\nIt seems that there is some kind of race with `test_free_threading.test_monitoring`, specifically the `sys.settrace` tests:\nhttps://github.com/python/cpython/blob/fba5dded6df3c2b1943557afef89a5cb418f65a2/Lib/test/test_free_threading/test_monitoring.py#L143-L166.\n\nThis was initially spotted in a buildbot failure here: https://buildbot.python.org/#/builders/1610/builds/1590. There have been a few behaviors noted:\n\n- refleaks causing a test failure\n- assertion failures\n- presumed deadlocks or other contention causing the tests to run extremely slowly (timing out after 45 minutes)\n- tests pass without issue 😬 \n\nThe variety of failure modes makes me think there is some kind of thread safety issue lurking behind the failures...\n\nAfter some local debugging (the remote debugger rocks!), I was able to reproduce the extremely long test run of `test_freethreading`, and narrow down the majority of the time being in the `sys.settrace` tests. My command line was:\n```\n./python -E -m test --timeout=2700 -R 3:3 -u-cpu -j10 test_free_threading\n```\nOn my x86 laptop on Ubuntu 24.04/WSL.\n\nReading over the test, it isn't clear to me what is meant to be tested. [sys.settrace only affects the current thread according to the docs](https://docs.python.org/3/library/sys.html#sys.settrace) (indeed, the C code sets the trace function to the current threadstate), so currently it is only checking that the main thread executes a frame of some sort. \n\nI didn't have time to find the root cause of the weird behavior above, so I'm filing this bug to note down my findings.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/emmatyping","@type":"Person","name":"emmatyping"},"datePublished":"2025-06-17T18:12:47Z","url":"https://github.com/python/cpython/issues/135633"}
| 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:3554e6c7-e63f-9538-9aca-913622d6bc4e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C4CA:6365:369380B:48C68AD:6B0211E9 |
| html-safe-nonce | 6304d1bb1c540a3ab4c9a191e8cdcc31ab0ec3b6afb1f78461a1a4412e5e9187 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNENBOjYzNjU6MzY5MzgwQjo0OEM2OEFEOjZCMDIxMUU5IiwidmlzaXRvcl9pZCI6IjE2MDY0OTA1MzU1NTg3NzkzNjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 75f1cc794bda6305933d14d8d1e2947bd685782bb4fa114397950554f74e3b91 |
| hovercard-subject-tag | issue:3154356366 |
| 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/135633/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c65f5bba6592ce6982b6daf97644ae7b4c9fdd95bf5cdf9af702f1e2cc1238a/python/cpython/issues/135633 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c65f5bba6592ce6982b6daf97644ae7b4c9fdd95bf5cdf9af702f1e2cc1238a/python/cpython/issues/135633 |
| og:image:alt | Bug report Bug description: It seems that there is some kind of race with test_free_threading.test_monitoring, specifically the sys.settrace tests: cpython/Lib/test/test_free_threading/test_monitor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | emmatyping |
| 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