René's URL Explorer Experiment


Title: `intern_common` should use `_Py_LOCK_DONT_DETACH` · Issue #149162 · python/cpython · GitHub

Open Graph Title: `intern_common` should use `_Py_LOCK_DONT_DETACH` · Issue #149162 · python/cpython

X Title: `intern_common` should use `_Py_LOCK_DONT_DETACH` · Issue #149162 · python/cpython

Description: Bug report PyUnicode_InternFromString and various other interning functions call intern_common, which locks an interpreter-wide lock in the free threading build. We should use _Py_LOCK_DONT_DETACH when locking that lock to avoid potentia...

Open Graph Description: Bug report PyUnicode_InternFromString and various other interning functions call intern_common, which locks an interpreter-wide lock in the free threading build. We should use _Py_LOCK_DONT_DETACH ...

X Description: Bug report PyUnicode_InternFromString and various other interning functions call intern_common, which locks an interpreter-wide lock in the free threading build. We should use _Py_LOCK_DONT_DETACH ...

Opengraph URL: https://github.com/python/cpython/issues/149162

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`intern_common` should use `_Py_LOCK_DONT_DETACH`","articleBody":"# Bug report\n\n`PyUnicode_InternFromString` and various other interning functions call `intern_common`, which locks an interpreter-wide lock in the free threading build. We should use `_Py_LOCK_DONT_DETACH` when locking that lock to avoid potential deadlocks in certain extensions.\n\nPyTorch, TensorFlow, and possibly other extensions use C++11 one time initialization via function local statics to intern string. For example:\n\n```c++\nvoid PyNode::compiled_args(CompiledNodeArgs& args) const {\n  static PyObject* method_name = PyUnicode_InternFromString(\"_compiled_autograd_key\");\n  ...\n}\n```\n\nhttps://github.com/pytorch/pytorch/blob/8804b122355d1aa1cc6bfffd1516f3df39f96c5f/torch/csrc/autograd/python_function.cpp#L369-L370\n\nC++ static locals implement thread-safe one time initialization, similar to `std::call_once` or `pthread_once`. That means that a (hidden) C++ lock is held during the call to `PyUnicode_InternFromString`. If we detach, during `PyUnicode_InternFromString`, we risk a lock ordering deadlock.\n\nHere's a complicated scenario that could deadlock:\n\n* Thread 1: requests a stop the world pause\n* Thread 2: holds the interned mutex (causes lock contention)\n* Thread 3: calls  `static PyObject* method_name = PyUnicode_InternFromString(...)`. Blocks on interned mutex and **detaches** for stop the world pause\n* Thread 4: calls `static PyObject* method_name = PyUnicode_InternFromString(...)` and blocks on C++ one time initialization lock **without detaching**.\n\nSo there's a deadlock where Thread 4 - (waiting on) -> Thread 3 - (waiting on) -> Thread 1 - (waiting on) -> Thread 4.\n\nThis isn't a problem in GIL-enabled builds because thread 3 won't block during `PyUnicode_InternFromString`.\n\n`_Py_LOCK_DONT_DETACH` prevents this problem because `PyUnicode_InternFromString()` will no longer block on a stop the world if there's contention on the interned mutex.\n\nNote that if callers used something like pybind11's `gil_safe_call_once_and_store` that would also avoid the deadlock.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149164\n* gh-153814\n* gh-153815\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2026-04-29T18:37:07Z","url":"https://github.com/python/cpython/issues/149162"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:04838f1e-1aaf-be95-edeb-597e2672660c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id88D4:350D1F:33F573:45F889:6AECC8CF
html-safe-nonce576a9fd0d5f978c0caa9edc4640f5b26ac35bd867714279941230b8e48fec824
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEQ0OjM1MEQxRjozM0Y1NzM6NDVGODg5OjZBRUNDOENGIiwidmlzaXRvcl9pZCI6IjQzNjQ5NzE2ODcwMTA5NDUyMzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaceb462185e2163e955f555d05669a780609857eb964fbdefd2381a81967d37261
hovercard-subject-tagissue:4352850873
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149162/issue_layout
twitter:imagehttps://opengraph.githubassets.com/994b43fd1224dc83cf41907c5e2c921594b125f98b4f2f07507179e521549983/python/cpython/issues/149162
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/994b43fd1224dc83cf41907c5e2c921594b125f98b4f2f07507179e521549983/python/cpython/issues/149162
og:image:altBug report PyUnicode_InternFromString and various other interning functions call intern_common, which locks an interpreter-wide lock in the free threading build. We should use _Py_LOCK_DONT_DETACH ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecolesbury
hostnamegithub.com
expected-hostnamegithub.com
Nonedc0b519c5798dc1150b88dc4c06a8b9634d0069218dc04e469970e76aad74016
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedb139f0bf57b59bf9a8c4abb0849924d6c6ca559
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/149162#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149162
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149162
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/149162
Reloadhttps://github.com/python/cpython/issues/149162
Reloadhttps://github.com/python/cpython/issues/149162
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.3k (2.3k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/pulse
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/149162
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/149162
intern_common should use _Py_LOCK_DONT_DETACHhttps://github.com/python/cpython/issues/149162#top
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/colesbury
colesburyhttps://github.com/colesbury
on Apr 29, 2026https://github.com/python/cpython/issues/149162#issue-4352850873
https://github.com/pytorch/pytorch/blob/8804b122355d1aa1cc6bfffd1516f3df39f96c5f/torch/csrc/autograd/python_function.cpp#L369-L370https://github.com/pytorch/pytorch/blob/8804b122355d1aa1cc6bfffd1516f3df39f96c5f/torch/csrc/autograd/python_function.cpp#L369-L370
gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common #149164https://github.com/python/cpython/pull/149164
[3.15] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) #153814https://github.com/python/cpython/pull/153814
[3.14] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) #153815https://github.com/python/cpython/pull/153815
colesburyhttps://github.com/colesbury
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
on Apr 29, 2026https://github.com/python/cpython/issues/149162#event-25003840393
StanFromIrelandhttps://github.com/StanFromIreland
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Apr 29, 2026https://github.com/python/cpython/issues/149162#event-25006976672
colesburyhttps://github.com/colesbury
on May 21, 2026https://github.com/python/cpython/issues/149162#event-25809994181
Merge branch 'main' into pythongh-149162-intern-common-lock-dont-detachhttps://github.com/colesbury/cpython/commit/36a25cd59534d740b3b9dde19b915657a36da631
pythongh-149162https://github.com/python/cpython/issues/149162
36a25cdhttps://github.com/colesbury/cpython/commit/36a25cd59534d740b3b9dde19b915657a36da631
naschemehttps://github.com/nascheme
on Jul 16, 2026https://github.com/python/cpython/issues/149162#event-28083696306
gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164)https://github.com/python/cpython/commit/f62050d65743f0c895f7e6d665936c4e86aa39d5
gh-149162https://github.com/python/cpython/issues/149162
gh-149164https://github.com/python/cpython/pull/149164
f62050dhttps://github.com/python/cpython/commit/f62050d65743f0c895f7e6d665936c4e86aa39d5
[3.14] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164)…https://github.com/python/cpython/commit/f5c4880151b609e0a0a0b05c292d36b18038c061
gh-149162https://github.com/python/cpython/issues/149162
gh-149164https://github.com/python/cpython/pull/149164
f5c4880https://github.com/python/cpython/commit/f5c4880151b609e0a0a0b05c292d36b18038c061
[3.15] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164)…https://github.com/python/cpython/commit/38c3f112c383d1f61a3e2d2d4ff589a5ca570944
gh-149162https://github.com/python/cpython/issues/149162
gh-149164https://github.com/python/cpython/pull/149164
38c3f11https://github.com/python/cpython/commit/38c3f112c383d1f61a3e2d2d4ff589a5ca570944
kumaraditya303https://github.com/kumaraditya303
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 24, 2026https://github.com/python/cpython/issues/149162#event-28433748545
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/149162
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/149162
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.