Title: gh-149504: Fix re-entrancy bug when .pth/.start file invokes site.addsitedir() by warsaw · Pull Request #149659 · python/cpython · GitHub
Open Graph Title: gh-149504: Fix re-entrancy bug when .pth/.start file invokes site.addsitedir() by warsaw · Pull Request #149659 · python/cpython
X Title: gh-149504: Fix re-entrancy bug when .pth/.start file invokes site.addsitedir() by warsaw · Pull Request #149659 · python/cpython
Description: Fix site.addsitedir() to allow re-entrant calls from within startup files. Previously, a .pth file containing an import line that called site.addsitedir() (or a .start entry point doing the same) could crash with RuntimeError: dictionary changed size during iteration during site initialization, breaking tools such as uv run --with. mkdir -p /tmp/site-repro/root /tmp/site-repro/overlay printf 'import site; site.addsitedir("/tmp/site-repro/overlay")\n' > /tmp/site-repro/root/reenter.pth ./python.exe -S -c 'import site; site.addsitedir("/tmp/site-repro/root"); print("done")' prints "done" for me. uv run --python /Users/jelle/py/cpython/python.exe --with iniconfig python -c 'import iniconfig' does not crash. The implementation is more comprehensive than #149516 and is more inline with a suggestion @ncoghlan made on the original PR. Thanks @zsol for providing your PR. @JelleZijlstra please take a look. Issue: gh-149504
Open Graph Description: Fix site.addsitedir() to allow re-entrant calls from within startup files. Previously, a .pth file containing an import line that called site.addsitedir() (or a .start entry point doing the same) ...
X Description: Fix site.addsitedir() to allow re-entrant calls from within startup files. Previously, a .pth file containing an import line that called site.addsitedir() (or a .start entry point doing the same) ...
Opengraph URL: https://github.com/python/cpython/pull/149659
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:9339f8a1-fd0a-abee-9e06-36342e5f24e8 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D05C:35E4DB:8A2310:C40E98:6A56594B |
| html-safe-nonce | 398c2051fc099baf7e845619fa290fc4a7bfee9a464c751121e929865251d91d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDVDOjM1RTREQjo4QTIzMTA6QzQwRTk4OjZBNTY1OTRCIiwidmlzaXRvcl9pZCI6IjM0NTUzMjI2NjYyNTI1MjM4NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 86d6aadc921e93458a5cce7a729f79e987225b320b355cf6795faeb11bb6de8c |
| hovercard-subject-tag | pull_request:3659873785 |
| 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/149659/files |
| twitter:image | https://avatars.githubusercontent.com/u/210184?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/210184?s=400&v=4 |
| og:image:alt | Fix site.addsitedir() to allow re-entrant calls from within startup files. Previously, a .pth file containing an import line that called site.addsitedir() (or a .start entry point doing the same) ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cffc1b7eb44a3dbb1e61c2a0523cad1f04e0368d730bf85ac498c992baf19e7d |
| 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 | 233d2274d9c68198aa6cb23d1db680b5c0b58bba |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width