GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.13] gh-130094: Fix race conditions in `importlib` (gh-130101) (gh-… · python/cpython@b0a181d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/importlib
    • _bootstrap.py
  • Misc/NEWS.d/next/Core_and_Builtins
    • 2025-02-14-00-32-52.gh-issue-130094.m3EF9E.rst
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/importlib/_bootstrap.py‎

Copy file name to clipboardExpand all lines: Lib/importlib/_bootstrap.py
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,9 @@ def _find_spec(name, path, target=None):
12451245
raise ImportError("sys.meta_path is None, Python is likely "
12461246
"shutting down")
12471247

1248+
# gh-130094: Copy sys.meta_path so that we have a consistent view of the
1249+
# list while iterating over it.
1250+
meta_path = list(meta_path)
12481251
if not meta_path:
12491252
_warnings.warn('sys.meta_path is empty', ImportWarning)
12501253

@@ -1299,7 +1302,6 @@ def _sanity_check(name, package, level):
12991302

13001303

13011304
_ERR_MSG_PREFIX = 'No module named '
1302-
_ERR_MSG = _ERR_MSG_PREFIX + '{!r}'
13031305

13041306
def _find_and_load_unlocked(name, import_):
13051307
path = None
@@ -1309,15 +1311,22 @@ def _find_and_load_unlocked(name, import_):
13091311
if parent not in sys.modules:
13101312
_call_with_frames_removed(import_, parent)
13111313
# Crazy side-effects!
1312-
if name in sys.modules:
1313-
return sys.modules[name]
1314+
module = sys.modules.get(name)
1315+
if module is not None:
1316+
return module
13141317
parent_module = sys.modules[parent]
13151318
try:
13161319
path = parent_module.__path__
13171320
except AttributeError:
13181321
msg = f'{_ERR_MSG_PREFIX}{name!r}; {parent!r} is not a package'
13191322
raise ModuleNotFoundError(msg, name=name) from None
13201323
parent_spec = parent_module.__spec__
1324+
if getattr(parent_spec, '_initializing', False):
1325+
_call_with_frames_removed(import_, parent)
1326+
# Crazy side-effects (again)!
1327+
module = sys.modules.get(name)
1328+
if module is not None:
1329+
return module
13211330
child = name.rpartition('.')[2]
13221331
spec = _find_spec(name, path)
13231332
if spec is None:
Collapse file

‎Misc/NEWS.d/next/Core_and_Builtins/2025-02-14-00-32-52.gh-issue-130094.m3EF9E.rst‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix two race conditions involving concurrent imports that could lead to
2+
spurious failures with :exc:`ModuleNotFoundError`.

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.