Skip to content

Commit 9d0252f

Browse files
miss-islingtongraingertblurb-it[bot]bswck
authored
[3.13] gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe (GH-126776) (#127778)
gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe (GH-126776) (cherry picked from commit 2233c30) Co-authored-by: Thomas Grainger <[email protected]> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Bartosz Sławecki <[email protected]>
1 parent 6441d42 commit 9d0252f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/linecache.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ def checkcache(filename=None):
4949
(This is not checked upon each call!)"""
5050

5151
if filename is None:
52-
filenames = list(cache.keys())
53-
elif filename in cache:
54-
filenames = [filename]
52+
# get keys atomically
53+
filenames = cache.copy().keys()
5554
else:
56-
return
55+
filenames = [filename]
5756

5857
for filename in filenames:
59-
entry = cache[filename]
58+
try:
59+
entry = cache[filename]
60+
except KeyError:
61+
continue
62+
6063
if len(entry) == 1:
6164
# lazy cache entry, leave it lazy.
6265
continue
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe.

0 commit comments

Comments
 (0)