Title: GH-83065: Fix import deadlock by implementing hierarchical module locking by gpshead · Pull Request #137196 · python/cpython · GitHub
Open Graph Title: GH-83065: Fix import deadlock by implementing hierarchical module locking by gpshead · Pull Request #137196 · python/cpython
X Title: GH-83065: Fix import deadlock by implementing hierarchical module locking by gpshead · Pull Request #137196 · python/cpython
Description: When one thread imports pkg.sub.mod and another thread imports pkg.sub and pkg/sub/__init__.py itself imports pkg.sub.mod, the two threads can acquire the per-module locks in opposite orders and trip the import system's deadlock detector, raising _DeadlockError to user code. This change makes _find_and_load() acquire the module locks for the full dotted-name chain (parent before child) when loading a nested module, so both threads contend on the same first lock and serialise instead of deadlocking. When acquiring a parent's lock would itself deadlock with another thread that is loading that parent (cross-package circular imports), the parent's lock is skipped and the partially-initialised parent is accepted -- the same policy _lock_unlock_module() already applies on the existing code path -- so concurrent circular imports that worked before continue to work. A second new test covers that cross-package case. The hot path (the module is already fully loaded) does not reach the new locking code at all. Fixes #83065 Issue: gh-83065
Open Graph Description: When one thread imports pkg.sub.mod and another thread imports pkg.sub and pkg/sub/__init__.py itself imports pkg.sub.mod, the two threads can acquire the per-module locks in opposite orders and tr...
X Description: When one thread imports pkg.sub.mod and another thread imports pkg.sub and pkg/sub/__init__.py itself imports pkg.sub.mod, the two threads can acquire the per-module locks in opposite orders and tr...
Opengraph URL: https://github.com/python/cpython/pull/137196
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e114d7e7-bdd4-3dec-a10e-28a49754132e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 892A:877A:2BC8AC:3A04BF:6A52CA47 |
| html-safe-nonce | 8c55da59c66d4d3781ad21de13b09a5557abefe91fbcd20e73eb6093786f3b9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTJBOjg3N0E6MkJDOEFDOjNBMDRCRjo2QTUyQ0E0NyIsInZpc2l0b3JfaWQiOiI4NDgzNjM5MTA4NDc0NDk2NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 95ee8476688f529e96ca6c837941c08c3471f936ea81d825af5386dbdfccbf00 |
| hovercard-subject-tag | pull_request:2702682229 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/137196/files |
| twitter:image | https://avatars.githubusercontent.com/u/68491?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/68491?s=400&v=4 |
| og:image:alt | When one thread imports pkg.sub.mod and another thread imports pkg.sub and pkg/sub/__init__.py itself imports pkg.sub.mod, the two threads can acquire the per-module locks in opposite orders and tr... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width