Title: Interpreter shutdown can deadlock when a daemon thread holds the warnings lock · Issue #159485 · python/cpython · GitHub
Open Graph Title: Interpreter shutdown can deadlock when a daemon thread holds the warnings lock · Issue #159485 · python/cpython
X Title: Interpreter shutdown can deadlock when a daemon thread holds the warnings lock · Issue #159485 · python/cpython
Description: Originally reported by @krassowski in #158973. A daemon thread can be stopped while holding the warnings lock. During interpreter finalization, garbage collection triggers a ResourceWarning, deadlocking the finalizing thread: import thre...
Open Graph Description: Originally reported by @krassowski in #158973. A daemon thread can be stopped while holding the warnings lock. During interpreter finalization, garbage collection triggers a ResourceWarning, deadlo...
X Description: Originally reported by @krassowski in #158973. A daemon thread can be stopped while holding the warnings lock. During interpreter finalization, garbage collection triggers a ResourceWarning, deadlo...
Opengraph URL: https://github.com/python/cpython/issues/159485
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Interpreter shutdown can deadlock when a daemon thread holds the warnings lock","articleBody":"Originally reported by @krassowski in #158973.\n\nA daemon thread can be stopped while holding the warnings lock. During interpreter finalization, garbage collection triggers a `ResourceWarning`, deadlocking the finalizing thread:\n\n```python\nimport threading\nimport time\nimport warnings\n\nready = threading.Event()\nwarnings.simplefilter(\"always\", ResourceWarning)\n\nclass WarnAtShutdown:\n def __init__(self):\n self.self_ref = self # Defer __del__ until shutdown GC.\n\n def __del__(self):\n warnings.warn(\"late\", ResourceWarning)\n\ndef showwarning(message, *args, **kwargs):\n if str(message) == \"hold\":\n ready.set()\n time.sleep(0.1)\n\nwarnings.showwarning = showwarning\nthreading.Thread(\n target=lambda: warnings.warn(\"hold\", ResourceWarning),\n daemon=True,\n).start()\nassert ready.wait(4)\nWarnAtShutdown()\n```\n\nExpected: the process exits normally. Actual: it hangs during interpreter shutdown.\n\n- **CPython versions tested on:** `3.14.8`, `3.15.0`.\n- **Operating systems tested on:** `macOS`.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-159488\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ngoldbaum","@type":"Person","name":"ngoldbaum"},"datePublished":"2026-10-15T20:32:03Z","url":"https://github.com/python/cpython/issues/159485"}
| 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:dfbc310a-cac8-1043-25c4-3f0d0de00b94 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E88:F8C5C:B8A802:E844B5:6B021B37 |
| html-safe-nonce | b15b49a293f7aaa0b0b89561925984704933eb771d949e696f451f3139446091 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTg4OkY4QzVDOkI4QTgwMjpFODQ0QjU6NkIwMjFCMzciLCJ2aXNpdG9yX2lkIjoiNDc2MDg4NjUxODI5NjQ4NDY2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c987d0bba11672e3f33415ce63132abcaa36efe7f0f682321e19ab1dbfa92958 |
| hovercard-subject-tag | issue:5873460855 |
| 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/159485/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2e2929d183d199b3185227f40a6955f7eac86225bfae86b8ebd98831a94f2e79/python/cpython/issues/159485 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2e2929d183d199b3185227f40a6955f7eac86225bfae86b8ebd98831a94f2e79/python/cpython/issues/159485 |
| og:image:alt | Originally reported by @krassowski in #158973. A daemon thread can be stopped while holding the warnings lock. During interpreter finalization, garbage collection triggers a ResourceWarning, deadlo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ngoldbaum |
| 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