]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe (#126776)
authorThomas Grainger <tagrain@gmail.com>
Tue, 10 Dec 2024 07:40:54 +0000 (07:40 +0000)
committerGitHub <noreply@github.com>
Tue, 10 Dec 2024 07:40:54 +0000 (08:40 +0100)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bartosz Sławecki <bartoszpiotrslawecki@gmail.com>
Lib/linecache.py
Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst [new file with mode: 0644]

index 4b38a0464d8747c50a6befde3e86fa0110ab58e6..8ba2df73d5a8fb85250c581417768cf7bc4f675e 100644 (file)
@@ -49,14 +49,17 @@ def checkcache(filename=None):
     (This is not checked upon each call!)"""
 
     if filename is None:
-        filenames = list(cache.keys())
-    elif filename in cache:
-        filenames = [filename]
+        # get keys atomically
+        filenames = cache.copy().keys()
     else:
-        return
+        filenames = [filename]
 
     for filename in filenames:
-        entry = cache[filename]
+        try:
+            entry = cache[filename]
+        except KeyError:
+            continue
+
         if len(entry) == 1:
             # lazy cache entry, leave it lazy.
             continue
diff --git a/Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst b/Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst
new file mode 100644 (file)
index 0000000..429fc2a
--- /dev/null
@@ -0,0 +1 @@
+Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe.