cpython/Lib
Miss Islington (bot) 7d074702eb
[3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) (#144662)
gh-143650: Fix importlib race condition on import failure (GH-143651)

Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:

1. Thread 1 starts importing, adds module to sys.modules
2. Thread 2 sees the module in sys.modules via the fast path
3. Thread 1's import fails, removes module from sys.modules
4. Thread 2 returns a stale module reference not in sys.modules

The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.
(cherry picked from commit ac8b5b6890)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 06:06:51 +00:00
..
__phello__
_pyrepl [3.14] gh-69605: Check for already imported modules in PyREPL module completion (GH-143438) 2026-01-05 19:47:26 +01:00
asyncio [3.14] gh-140648: Make asyncio REPL respect the -I flag (isolated mode) (GH-143045) (#143383) 2026-01-03 08:29:05 +00:00
collections [3.14] gh-140911: Ensure that UserString.index() and UserString.rindex() accept UserString as argument (GH-140945) (GH-141946) 2025-11-25 13:56:05 +00:00
compression [3.14] gh-132983: Split `_zstd_set_c_parameters` (GH-133921) (#134838) 2025-05-28 17:25:06 +01:00
concurrent [3.14] gh-141125: delete unused import textwrap in interpreter.py (GH-141126) (#141177) 2025-11-07 00:29:25 +00:00
ctypes [3.14] gh-140041: Fix import of ctypes on Android and Cygwin when ABI flags are present (GH-140178) (#140180) 2025-10-15 22:08:35 +00:00
curses
dbm [3.14] gh-135386: Fix "unable to open database file" errors on readonly DB (GH-135566) (GH-138056) 2025-10-08 11:41:09 +03:00
email [3.14] gh-144125: email: verify headers are sound in BytesGenerator (#144182) 2026-01-25 19:18:08 +02:00
encodings [3.14] gh-135069: Fix exception message in encodings.idna module (GH-135071) (#136235) 2025-07-03 10:18:27 +00:00
ensurepip [3.14] gh-144538: Upgrade bundled pip to 26.0.1 (gh-144556) (#144562) 2026-02-07 14:22:45 +02:00
html [3.14] gh-140875: Fix handling of unclosed charrefs before EOF in HTMLParser (GH-140904) (GH-141745) 2025-11-19 12:43:24 +00:00
http [3.14] gh-143919: Reject control characters in http cookies (#144089) 2026-01-23 13:44:29 +02:00
idlelib [3.14] gh-135142: Initial 3.15 News3.txt entries (GH-144200) (#144201) 2026-01-23 22:16:00 -05:00
importlib [3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) (#144662) 2026-02-11 06:06:51 +00:00
json [3.14] gh-140793: Improve documentatation and tests for the ensure_ascii option in the json module (GH-140906) (GH-141227) 2025-11-08 10:32:44 +00:00
logging [3.14] gh-143237: Fix support of named pipes in the rotating logging handlers (GH-143259) (#143297) 2026-01-25 17:11:45 +00:00
multiprocessing [3.14] gh-143706: Fix sys.argv not set during multiprocessing forkserver __main__ preload (GH-143717) (#143763) 2026-01-13 00:13:41 +00:00
pathlib [3.14] GH-133789: Fix unpickling of pathlib objects pickled in Python 3.13 (GH-133831) (#140276) 2025-10-17 22:23:01 +00:00
pydoc_data Python 3.14.3 2026-02-03 17:32:20 +02:00
re [3.14] Revert "gh-140797: Forbid capturing groups in re.Scanner lexicon patterns (GH-140944) (GH-140982)" (#142309) 2025-12-05 16:45:15 +00:00
site-packages
sqlite3 [3.14] gh-133439: Fix dot commands with trailing spaces are mistaken for multi-line sqlite statements in the sqlite3 command-line interface (GH-133440) (GH-133738) 2025-05-09 15:17:24 +03:00
string [3.14] GH-132661: Add `string.templatelib.convert()` (GH-135217) (#136671) 2025-07-15 10:22:24 +00:00
sysconfig [3.14] Synced docs and docstring for sysconfig.get_platform (GH-135530) (#138976) 2025-10-04 17:55:25 +03:00
test [3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) (#144662) 2026-02-11 06:06:51 +00:00
tkinter [3.14] gh-143754: Modernize Tkinter docs (GH-143841) (GH-144032) 2026-01-19 12:27:32 +00:00
tomllib gh-133117: Enable stricter mypy checks for tomllib (#133206) 2025-05-03 16:57:09 +03:00
turtledemo gh-128062: Fix the font size and shortcut display of the turtledemo menu (#128063) 2024-12-19 15:24:47 -05:00
unittest [3.14] gh-142651: make Mock.call_count thread-safe (GH-142656) (#142743) 2025-12-15 18:21:52 +05:30
urllib [3.14] gh-144148: Update the urllib.parse documentation (GH-144497) (GH-144507) 2026-02-05 17:24:24 +02:00
venv [3.14] gh-134060: Don't create a certain symlink in venv if platform does not support it (GH-134061) 2025-05-18 22:33:14 +03:00
wsgiref [3.14] gh-143916: Reject control characters in wsgiref.headers.Headers (GH-143917) (#143972) 2026-01-17 18:11:52 +00:00
xml [3.14] gh-142754: Ensure that Element & Attr instances have the ownerDocument attribute (GH-142794) (#142818) 2025-12-20 15:56:47 -08:00
xmlrpc [3.14] gh-136839: Refactor simple dict.update calls (GH-136811) (#136840) 2025-07-19 17:36:31 +00:00
zipfile [3.14] gh-139700: Check consistency of the zip64 end of central directory record (GH-139702) (GH-139706) 2025-10-07 23:16:26 +02:00
zoneinfo [3.14] gh-143241: Fix infinite loop in zoneinfo._common.load_data (GH-143243) (#143251) 2025-12-28 15:14:04 +00:00
__future__.py
__hello__.py
_aix_support.py
_android_support.py [3.14] gh-144415: Android testbed fixes (GH-142912) (#144416) 2026-02-03 17:18:49 +08:00
_apple_support.py gh-126925: Modify how iOS test results are gathered (#127592) 2024-12-09 13:28:57 +08:00
_ast_unparse.py [3.14] gh-138774: use value to ast.unparse code when str is None in ast.Interpolation (GH-139415) (#140503) 2025-10-23 14:39:02 +00:00
_collections_abc.py [3.14] gh-118803: Improve documentation around ByteString deprecation (GH-139115) (#139136) 2025-09-18 17:54:43 +00:00
_colorize.py [3.14] gh-141570: can_colorize: Expect fileno() to raise OSError, as documented (GH-141716) (#141747) 2025-11-19 14:29:15 +00:00
_compat_pickle.py
_ios_support.py
_markupbase.py _markupbase.py: Use a permalink for the analysis of MS-Word extensions (GH-129017) 2025-02-06 11:40:43 +01:00
_opcode_metadata.py gh-100239: specialize BINARY_OP/SUBSCR for list-slice (#132626) 2025-05-01 10:28:52 +00:00
_osx_support.py
_py_abc.py
_py_warnings.py [3.14] gh-140691: urllib.request: Close FTP control socket if data socket can't connect (GH-140835) (GH-141555) 2025-11-14 17:27:33 +01:00
_pydatetime.py [3.14] gh-123681: Check NORMALIZE_CENTURY behavior at runtime; require C99 (GH-136022) (GH-137947) 2025-10-07 19:59:06 +02:00
_pydecimal.py [3.14] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836) (#140105) 2025-10-14 15:44:30 +02:00
_pyio.py [3.14] gh-143602: Fix duplicate buffer exports in io.BytesIO.write (#143629) (#143872) 2026-01-15 16:02:46 +00:00
_pylong.py Fix typos in comments and test code (#122846) 2024-08-11 21:16:41 -07:00
_sitebuiltins.py [3.14] gh-138897: Use _pyrepl.pager for _sitebuiltins._Printer (GH-138898) (GH-143364) 2026-01-02 17:27:09 +01:00
_strptime.py [3.14] gh-136028: Fix parsing month names containing "ฤฐ" (U+0130) in strptime() (GH-136029) (GH-136037) 2025-06-27 14:12:15 +00:00
_threading_local.py gh-107006: Move threading.local docstring to docs (#131840) 2025-05-05 15:00:15 +03:00
_weakrefset.py gh-89967: make WeakKeyDictionary and WeakValueDictionary thread safe (#125325) 2024-10-13 21:05:05 +05:30
abc.py
annotationlib.py [3.14] gh-143831: Compare cells by identity in forward references (GH-143848) (#144020) 2026-01-19 05:57:54 +00:00
antigravity.py
argparse.py [3.14] gh-112527: Fix help text for required options in argparse (GH-112528) (GH-142475) 2025-12-09 17:35:49 +00:00
ast.py [3.14] gh-134718: Fix ast.dump() for empty non-default values (GH-134926) (GH-134931) 2025-05-30 18:24:59 +03:00
base64.py [3.14] gh-138775: fix handle python -m base64 stdin correct with EOF signal (GH-138776) (#141432) 2025-11-12 00:12:57 +00:00
bdb.py [3.14] gh-136057: Allow step and next to step over for loops (GH-136160) (#141640) 2025-11-16 22:22:11 +00:00
bisect.py
bz2.py gh-132983: Introduce compression package and move _compression module (GH-133018) 2025-04-27 14:41:30 -07:00
calendar.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
cmd.py gh-133363: Fix Cmd completion for lines beginning with ! (#133364) 2025-05-03 22:50:37 -04:00
code.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
codecs.py [3.14] gh-52876: Implement missing parameter in codecs.StreamReaderWriter functions (GH-136498) (#136514) 2025-07-10 16:09:45 +00:00
codeop.py gh-132449: Improve syntax error messages for keywords with typos (#132450) 2025-04-22 11:01:55 +02:00
colorsys.py gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
compileall.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
configparser.py [3.14] gh-136282: Configparser: create unnamed sections via mapping protocol access (GH-136313) (GH-142978) 2026-01-06 16:46:04 +01:00
contextlib.py
contextvars.py gh-126451: Register contextvars.Context to collections.abc.Mapping (#126452) 2024-11-07 01:12:45 +03:00
copy.py gh-128118: Speed up copy.copy with fast lookup for atomic and container types (#128119) 2024-12-30 18:18:42 +01:00
copyreg.py gh-132882: Fix copying of unions with members that do not support __or__ (#132883) 2025-04-24 16:49:09 +00:00
cProfile.py gh-132737: Support profiling modules that require __main___ (#132738) 2025-04-24 14:41:01 -04:00
csv.py gh-118761: Improve import time for csv (#128858) 2025-01-18 11:45:18 +01:00
dataclasses.py [3.14] gh-142214: Fix two regressions in dataclasses (GH-142223) (#142277) 2025-12-05 08:08:15 +00:00
datetime.py gh-123843: Remove broken links to the Zope DateTimeWiki (#123846) 2024-09-08 22:39:23 -04:00
decimal.py gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes (GH-123613) 2024-09-28 20:51:49 +03:00
difflib.py [3.14] gh-128051: Fix tests if sys.float_repr_style is 'legacy' (GH-135908) (#136025) 2025-06-27 10:26:51 +00:00
dis.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
doctest.py [3.14] gh-136914: Fix support of cached functions and properties in DocTest's lineno computation (GH-136930) (#137616) 2025-10-07 20:48:10 +02:00
enum.py [3.14] gh-140806: add docs for enum.bin function (GH-140807) (#143726) 2026-01-12 12:01:01 +00:00
filecmp.py gh-122400: Handle ValueError in filecmp (GH-122401) 2024-07-30 08:50:30 +00:00
fileinput.py
fnmatch.py gh-133306: Use \z instead of \Z in fnmatch.translate() and glob.translate() (GH-133338) 2025-05-03 17:58:21 +03:00
fractions.py [3.14] gh-87790: support thousands separators for formatting fractional part of Fraction (GH-132204) (#136364) 2025-07-07 19:24:24 +03:00
ftplib.py
functools.py [3.14] gh-140873: Fix the singledispatchmethod documentation (GH-141523) 2025-11-18 13:16:39 +02:00
genericpath.py [3.14] gh-135034: Normalize link targets in tarfile, add os.path.realpath(strict='allow_missing') (gh-135037) (gh-135065) 2025-06-03 14:05:00 +02:00
getopt.py gh-126946: Improve error message in getopt.do_longs based on existing comment (GH-126871) 2024-11-26 10:54:02 +02:00
getpass.py [3.14] gh-138514: getpass: restrict echo_char to a single ASCII character (GH-138591) (#138988) 2025-09-17 17:20:45 +03:00
gettext.py gettext: Remove outdated "TODO" comment (#130890) 2025-03-06 23:41:03 +00:00
glob.py [3.14] docs: be clearer that glob results are unordered (GH-140184) (#140339) 2025-10-20 07:31:05 +03:00
graphlib.py gh-130914: Make graphlib.TopologicalSorter.prepare() idempotent (#131317) 2025-03-18 16:28:00 -05:00
gzip.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
hashlib.py [3.14] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134961) 2025-06-01 10:26:56 +02:00
heapq.py [3.14] gh-137239: Add *_max functions to heapq.__all__ (gh-137241) (#137256) 2025-10-07 23:22:07 +05:30
hmac.py [3.14] gh-142451: correctly copy HMAC attributes in HMAC.copy() (GH-142510) (#142698) 2025-12-14 09:27:03 +00:00
imaplib.py [3.14] gh-78319: Fix implementation of IMAP APPEND UTF8 (GH-9436) (GH-139406) 2025-10-07 22:12:30 +02:00
inspect.py [3.14] gh-144085: Add {gi,cr}_suspended to inspect comments and generator/coroutine tests (GH-144086) (#144104) 2026-01-21 11:02:35 +00:00
io.py gh-132952: Speed up startup by importing _io instead of io (#132957) 2025-04-28 08:38:56 -07:00
ipaddress.py [3.14] gh-141497: Make ipaddress.IP{v4,v6}Network.hosts() always returning an iterator (GH-141547) (GH-141673) 2025-11-17 17:56:55 +00:00
keyword.py
linecache.py [3.14] gh-133253: making linecache thread-safe (GH-133305) (gh-143910) 2026-01-16 13:34:38 -05:00
locale.py [3.14] gh-133967: Do not normalize locale name 'C.UTF-8' to 'en_US.UTF-8' (GH-135347) (GH-135349) 2025-06-11 12:43:20 +03:00
lzma.py gh-132983: Introduce compression package and move _compression module (GH-133018) 2025-04-27 14:41:30 -07:00
mailbox.py [3.14] gh-143010: Prevent a TOCTOU issue by only calling open once (GH-143011) (#143080) 2025-12-22 13:14:59 -05:00
mimetypes.py [3.14] gh-136507: Fix mimetypes CLI to handle multiple file parameters (GH-136508) (GH-138140) 2025-10-07 19:59:52 +02:00
modulefinder.py
netrc.py [3.14] gh-135815: skip netrc security checks if os.getuid is missing (GH-135816) (#135825) 2025-06-22 20:12:57 +00:00
ntpath.py [3.14] gh-136065: Fix quadratic complexity in os.path.expandvars() (GH-134952) (GH-140844) 2025-10-31 17:43:23 +01:00
nturl2path.py GH-125866: Deprecate nturl2path module (#131432) 2025-03-19 19:33:01 +00:00
numbers.py [3.14] gh-122450: Expand documentation for `Rational and Fraction` (GH-136800) (#137363) 2025-10-07 19:15:22 +01:00
opcode.py gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737) 2025-03-28 10:35:20 +00:00
operator.py gh-115808: Add `is_none and is_not_none to operator` (#115814) 2024-08-10 20:16:34 +01:00
optparse.py gh-118761: Redudce the import time of `optparse` (#128899) 2025-01-20 00:03:19 +00:00
os.py [3.14] gh-120057: add os.reload_environ to __all__ (GH-140763) (#140773) 2025-10-29 22:22:20 +00:00
pdb.py [3.14] gh-143874: Use self.message instead of raw print in _exec_in_closure() (GH-143875) (#144061) 2026-01-20 16:35:30 -08:00
pickle.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
pickletools.py [3.14] gh-139646: fix typo in pickletools error message (GH-139647) (GH-139649) 2025-10-07 20:19:01 +02:00
pkgutil.py gh-131152, pkgutil: Remove unused imports (#131149) 2025-03-12 15:03:36 +01:00
platform.py [3.14] gh-141600: Fix musl version detection on Void Linux (GH-141850) 2025-11-22 18:47:47 +00:00
plistlib.py [3.14] gh-143346: Fix calculation of the line width for wrapped Base64 in plistlib (GH-143347) (GH-143719) 2026-01-12 09:08:52 +00:00
poplib.py gh-130637: Add validation for numeric response data in stat() method (#130646) 2025-03-02 08:05:40 -05:00
posixpath.py [3.14] gh-136065: Fix quadratic complexity in os.path.expandvars() (GH-134952) (GH-140844) 2025-10-31 17:43:23 +01:00
pprint.py gh-118761: Improve import time of pprint (#122725) 2024-08-07 22:46:54 +03:00
profile.py
pstats.py gh-118761: Improve import time for pstats and zipfile (#128981) 2025-01-23 14:49:36 +00:00
pty.py gh-124405: Fix NameError in openpty (#124406) 2024-09-24 20:06:39 +02:00
py_compile.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
pyclbr.py
pydoc.py [3.14] gh-138568: Make help mode in PyREPL not exit on empty line input (GH-143512) (GH-143519) 2026-01-07 17:06:53 +01:00
queue.py [3.14] Fix Queue.shutdown docs for condition to unblock a join (gh-137088) (#141073) 2025-11-06 11:11:31 +05:30
quopri.py
random.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
reprlib.py [3.14] gh-135487: fix reprlib.Repr.repr_int when given very large integers (GH-135506) (#135887) 2025-06-24 12:02:02 +00:00
rlcompleter.py
runpy.py
sched.py gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
secrets.py
selectors.py
shelve.py
shlex.py [3.14] gh-138804: Check type in shlex.quote (GH-138809) (#138846) 2025-09-13 21:29:50 +03:00
shutil.py [3.14] gh-132983: Add missing references to Zstandard in shutil docstrings (GH-136617) (#137052) 2025-07-25 12:30:11 +03:00
signal.py
site.py [3.14] gh-138993: Dedent credits text (GH-138994) (#140088) 2025-10-15 14:05:47 +03:00
smtplib.py [3.14] gh-139434: Update selected RFC 2822 references to RFC 5322 (GH-139435) (#141025) 2025-11-04 16:23:16 -05:00
socket.py gh-128916: Do not set SO_REUSEPORT on non-AF_INET* sockets (GH-128933) 2025-01-17 16:49:16 -08:00
socketserver.py gh-128916: Do not set SO_REUSEPORT on non-AF_INET* sockets (GH-128933) 2025-01-17 16:49:16 -08:00
sre_compile.py
sre_constants.py
sre_parse.py
ssl.py [3.14] Docs: fix RFC index reference for TLS 1.3 (GH-142262) (#142340) 2025-12-06 14:51:08 +00:00
stat.py [3.14] gh-144050: Fix stat.filemode pure Python file type detection (GH-144059) (GH-144073) 2026-01-20 12:47:21 +00:00
statistics.py [3.14] gh-140938: Raise ValueError for infinite inputs to stdev/pstdev (GH-141531) (#141575) 2025-11-14 18:58:40 -08:00
stringprep.py
struct.py
subprocess.py [3.14] gh-142195: Fixed Popen.communicate indefinite loops (GH-143203) (#143255) 2025-12-28 17:22:47 +00:00
symtable.py gh-119698: deprecate `symtable.Class.get_methods` (#121902) 2024-07-22 07:04:17 -07:00
tabnanny.py
tarfile.py [3.14] gh-81325: Support path-like objects with streaming TarFile (GH-137188) (#137365) 2025-10-07 20:40:42 +02:00
tempfile.py [3.14] gh-132124: improve safety nets for creating AF_UNIX socket files (GH-134085) (#134447) 2025-05-21 17:36:32 +00:00
textwrap.py [3.14] gh-139065: Fix trailing space before long word in textwrap (GH-139070) (GH-139902) 2025-10-10 13:54:46 +00:00
this.py
threading.py [3.14] gh-114827: clarify threading.Event.wait timeout behavior (GH-114834) (#140100) 2025-10-14 14:13:33 +00:00
timeit.py gh-131178: Update help message for timeit CLI (#131326) 2025-03-30 14:19:38 +03:00
token.py gh-131507: Add support for syntax highlighting in PyREPL (GH-133247) 2025-05-02 20:22:31 +02:00
tokenize.py [3.14] gh-63161: Fix tokenize.detect_encoding() (GH-139446) (GH-140378) 2025-10-20 17:34:56 +00:00
trace.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
traceback.py [3.14] gh-137576: Fix for Basic REPL showing incorrect code in tracebacks with PYTHONSTARTUP (GH-137625) (#137771) 2025-08-27 18:28:20 +03:00
tracemalloc.py
tty.py
turtle.py [3.14] gh-138772: Fix and improve documentation for turtle color functions (GH-139325) (GH-140047) 2025-10-13 15:56:26 +00:00
types.py [3.14] gh-143999: Fix: handle suspended state on types.coroutine wrappers (GH-144000) (GH-144066) 2026-01-20 12:59:42 +02:00
typing.py [3.14] Update docstrings of typing.Hashable, typing.List, etc., to reflect their deprecation (GH-143295) (#143348) 2026-01-02 11:56:56 +00:00
uuid.py [3.14] gh-135244: generate UUID random Node ID with a CSPRNG as per RFC 9562, ยง6.10.3 (GH-135226) (#135255) 2025-06-08 12:13:04 +00:00
warnings.py gh-128384: Use a context variable for warnings.catch_warnings (gh-130010) 2025-04-09 16:18:54 -07:00
wave.py [3.14] gh-136523: Fix wave.Wave_write emitting an unraisable when open raises (GH-136529) (GH-136606) 2025-07-16 07:26:52 +00:00
weakref.py gh-89967: make WeakKeyDictionary and WeakValueDictionary thread safe (#125325) 2024-10-13 21:05:05 +05:30
webbrowser.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
zipapp.py gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
zipimport.py gh-125746: Delay deprecated zipimport.zipimporter.load_module removal time to 3.15 (#125748) 2025-02-11 23:59:09 +00:00