René's URL Explorer Experiment


Title: Concurrent imports of a package and its submodule raise _DeadlockError in 3.14 and since 3.13.16 · Issue #160045 · python/cpython · GitHub

Open Graph Title: Concurrent imports of a package and its submodule raise _DeadlockError in 3.14 and since 3.13.16 · Issue #160045 · python/cpython

X Title: Concurrent imports of a package and its submodule raise _DeadlockError in 3.14 and since 3.13.16 · Issue #160045 · python/cpython

Description: Bug description: Since the fix for gh-130094 (GH-130101, backported to 3.13 in GH-155915 and first released in 3.13.16), _find_and_load_unlocked() re-imports a parent package whose spec is still _initializing, and it does so while holdin...

Open Graph Description: Bug description: Since the fix for gh-130094 (GH-130101, backported to 3.13 in GH-155915 and first released in 3.13.16), _find_and_load_unlocked() re-imports a parent package whose spec is still _i...

X Description: Bug description: Since the fix for gh-130094 (GH-130101, backported to 3.13 in GH-155915 and first released in 3.13.16), _find_and_load_unlocked() re-imports a parent package whose spec is still _i...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Concurrent imports of a package and its submodule raise _DeadlockError in 3.14 and since 3.13.16","articleBody":"\n### Bug description:\n\nSince the fix for gh-130094 (GH-130101, backported to 3.13 in GH-155915 and first released in 3.13.16), `_find_and_load_unlocked()` re-imports a parent package whose spec is still `_initializing`, and it does so while holding the child module's lock. That creates a lock-order inversion between two common imports that worked before:\n\n- Thread A runs `import pkg`. It holds `pkg`'s module lock while `pkg/__init__.py` runs, and that file does `from .sub import X`, so A then needs the lock for `pkg.sub`.\n- Thread B runs `import pkg.sub` while `pkg` is still initializing. It takes the `pkg.sub` lock, sees `pkg.__spec__._initializing`, and now waits for `pkg`'s lock.\n\nimportlib detects the cycle and raises `_DeadlockError` in thread A. Up to 3.13.15, thread B loaded `pkg.sub` without waiting for the parent, so both imports succeeded. There is no import cycle in user code, and the same imports work in either order on a single thread.\n\nReproducer (fails every time on 3.13.16 and 3.14.4; passes on 3.13.13):\n\n```python\nimport os, sys, tempfile, threading, time\n\nroot = tempfile.mkdtemp()\nos.makedirs(os.path.join(root, \"pkg\"))\nwith open(os.path.join(root, \"pkg\", \"__init__.py\"), \"w\") as f:\n    f.write(\"import time\\ntime.sleep(0.5)\\nfrom .sub import X\\n\")\nwith open(os.path.join(root, \"pkg\", \"sub.py\"), \"w\") as f:\n    f.write(\"X = 1\\n\")\nsys.path.insert(0, root)\n\nerrors = []\n\ndef run(name):\n    try:\n        __import__(name)\n    except BaseException as e:\n        errors.append(f\"{name}: {type(e).__name__}: {e}\")\n\na = threading.Thread(target=run, args=(\"pkg\",))\nb = threading.Thread(target=run, args=(\"pkg.sub\",))\na.start()\ntime.sleep(0.1)  # pkg is now initializing; thread a holds its module lock\nb.start()\na.join(); b.join()\nprint(sys.version.split()[0], \"->\", errors or \"OK\")\n```\n\n```\n3.13.13 -> OK\n3.13.16 -> [\"pkg: _DeadlockError: deadlock detected by _ModuleLock('pkg.sub') at 0x...\"]\n3.14.4  -> [\"pkg: _DeadlockError: deadlock detected by _ModuleLock('pkg.sub') at 0x...\"]\n```\n\nRemoving only the new block below from 3.13.16's `_find_and_load_unlocked()` makes the reproducer pass. The `meta_path = list(meta_path)` part of the same change has no effect on it:\n\n```python\n        if getattr(parent_spec, '_initializing', False):\n            _call_with_frames_removed(import_, parent)\n        # Crazy side-effects (again)!\n        module = sys.modules.get(name)\n        if module is not None:\n            return module\n```\n\nReal-world impact: any package whose `__init__` imports its own submodules is affected (`requests`, `prometheus_client`, and so on) as soon as two threads import it and one of its submodules for the first time at once. The Datadog Agent loads Python checks from several threads and hit this right after moving to 3.13.16. Checks failed at startup with `_DeadlockError: deadlock detected by _ModuleLock('requests.exceptions')`, so we went back to 3.13.15 (DataDog/datadog-agent#57902). Other projects report the same error after upgrading to 3.13.16 or 3.14, for example gke-labs/kube-agents#2446, dgunning/edgartools#1325 and marimo-team/marimo#11095.\n\nBecause this is a regression in a bugfix release, could the 3.13 backport be reverted, or this part changed so the thread doesn't wait for the parent's lock while holding the child's? The same code is on 3.14 and `main`.\n\ngh-159963 is related but separate: it covers a 3.15-only change from gh-83065. This report is about the gh-130094 change that is already in 3.13.16 and 3.14.\n\n### CPython versions tested on:\n\n3.13, 3.14\n\n### Operating systems tested on:\n\nmacOS\n","author":{"url":"https://github.com/Kyle-Neale","@type":"Person","name":"Kyle-Neale"},"datePublished":"2026-10-21T15:31:11Z","url":"https://github.com/python/cpython/issues/160045"}

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:a7a53a38-515f-809c-7c31-b2f5fe6ad311
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD31C:210678:679565:8BC6D0:6AED2536
html-safe-nonce00d791843e4f09e15fc73e803201aed1421810d931c94d950da9cefd62443b6c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzFDOjIxMDY3ODo2Nzk1NjU6OEJDNkQwOjZBRUQyNTM2IiwidmlzaXRvcl9pZCI6IjUwNjgxODU2MjE1MjgxMjY3NzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac2be17ca9ea24aee43e7a1c129a2fe2e16747d505fba83c7841d96dccaf460636
hovercard-subject-tagissue:5963529457
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/160045/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0a0e134e4ed676516f05a64b1065fff5432b1030202b99d8012c3e84fcdec3df/python/cpython/issues/160045
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0a0e134e4ed676516f05a64b1065fff5432b1030202b99d8012c3e84fcdec3df/python/cpython/issues/160045
og:image:altBug description: Since the fix for gh-130094 (GH-130101, backported to 3.13 in GH-155915 and first released in 3.13.16), _find_and_load_unlocked() re-imports a parent package whose spec is still _i...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameKyle-Neale
hostnamegithub.com
expected-hostnamegithub.com
None9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2
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
release98b41fa4b5635ceb45a4c54320fced73817ff290
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/160045#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F160045
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%2F160045
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/160045
Reloadhttps://github.com/python/cpython/issues/160045
Reloadhttps://github.com/python/cpython/issues/160045
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/160045
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/160045
Concurrent imports of a package and its submodule raise _DeadlockError in 3.14 and since 3.13.16https://github.com/python/cpython/issues/160045#top
DataDog/datadog-agent#58597https://github.com/DataDog/datadog-agent/pull/58597
https://github.com/gpshead
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/Kyle-Neale
Kyle-Nealehttps://github.com/Kyle-Neale
on Oct 21, 2026https://github.com/python/cpython/issues/160045#issue-5963529457
gh-130094https://github.com/python/cpython/issues/130094
GH-130101https://github.com/python/cpython/pull/130101
GH-155915https://github.com/python/cpython/pull/155915
DataDog/datadog-agent#57902https://github.com/DataDog/datadog-agent/pull/57902
gke-labs/kube-agents#2446https://github.com/gke-labs/kube-agents/issues/2446
dgunning/edgartools#1325https://github.com/dgunning/edgartools/issues/1325
marimo-team/marimo#11095https://github.com/marimo-team/marimo/pull/11095
gh-159963https://github.com/python/cpython/issues/159963
gh-83065https://github.com/python/cpython/issues/83065
gh-130094https://github.com/python/cpython/issues/130094
NekoAsakurahttps://github.com/NekoAsakura
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%22
on Oct 21, 2026https://github.com/python/cpython/issues/160045#event-33862085697
ZeroIntensityhttps://github.com/ZeroIntensity
release-blockerhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22release-blocker%22
on Oct 21, 2026https://github.com/python/cpython/issues/160045#event-33878530463
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Oct 21, 2026https://github.com/python/cpython/issues/160045#event-33878536314
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Oct 21, 2026https://github.com/python/cpython/issues/160045
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Oct 21, 2026https://github.com/python/cpython/issues/160045#issuecomment-6324199758
@Yhg1shttps://github.com/Yhg1s
@hugovkhttps://github.com/hugovk
@colesburyhttps://github.com/colesbury
gh-worker-dd-mergequeue-cf854dhttps://github.com/apps/gh-worker-dd-mergequeue-cf854d
on Oct 23, 2026https://github.com/python/cpython/issues/160045#event-34081320670
Bump embedded Python to 3.13.17 with a patch for the importlib deadlo…https://github.com/DataDog/datadog-agent/commit/32374b0dd7f46f7f4e8acb41d98fd649a2710d7e
32374b0https://github.com/DataDog/datadog-agent/commit/32374b0dd7f46f7f4e8acb41d98fd649a2710d7e
https://github.com/gpshead
gpsheadhttps://github.com/gpshead
on Oct 25, 2026https://github.com/python/cpython/issues/160045#issuecomment-6391514759
#130094 (comment)https://github.com/python/cpython/issues/130094#issuecomment-6157942065
gh-83065https://github.com/python/cpython/issues/83065
gh-159963https://github.com/python/cpython/issues/159963
gh-155915https://github.com/python/cpython/pull/155915
gpsheadhttps://github.com/gpshead
release-blockerhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22release-blocker%22
on Oct 25, 2026https://github.com/python/cpython/issues/160045#event-34157496544
gpsheadhttps://github.com/gpshead
on Oct 25, 2026https://github.com/python/cpython/issues/160045#event-34157520793
gpsheadhttps://github.com/gpshead
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
on Oct 25, 2026https://github.com/python/cpython/issues/160045#event-34157530397
gpsheadhttps://github.com/gpshead
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Oct 25, 2026https://github.com/python/cpython/issues/160045
gpsheadhttps://github.com/gpshead
on Oct 25, 2026https://github.com/python/cpython/issues/160045#event-34157590879
AliDatadoghttps://github.com/AliDatadog
on Oct 26, 2026https://github.com/python/cpython/issues/160045#event-34277762866
[Backport 7.85.x] Bump embedded Python to 3.13.17 with a patch for th…https://github.com/DataDog/datadog-agent/commit/4e69192e9a79446305ea2650bc63f8d80b07886f
4e69192https://github.com/DataDog/datadog-agent/commit/4e69192e9a79446305ea2650bc63f8d80b07886f
gh-worker-dd-mergequeue-cf854dhttps://github.com/apps/gh-worker-dd-mergequeue-cf854d
on Oct 26, 2026https://github.com/python/cpython/issues/160045#event-34289329023
Bump AIX embedded Python to 3.13.17 with the importlib deadlock patch (…https://github.com/DataDog/datadog-agent/commit/6a20b747f119e0fb97386f91b1e4b0315b9aa820
…https://github.com/DataDog/datadog-agent/pull/58631
6a20b74https://github.com/DataDog/datadog-agent/commit/6a20b747f119e0fb97386f91b1e4b0315b9aa820
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/160045
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/160045
gpsheadhttps://github.com/gpshead
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%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.