Skip to content

Commit e881dd1

Browse files
miss-islingtongraingertblurb-it[bot]bswck
authored
[3.12] gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe (GH-126776) (#127779)
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 fa93522 commit e881dd1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/linecache.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ def checkcache(filename=None):
5454
(This is not checked upon each call!)"""
5555

5656
if filename is None:
57-
filenames = list(cache.keys())
58-
elif filename in cache:
59-
filenames = [filename]
57+
# get keys atomically
58+
filenames = cache.copy().keys()
6059
else:
61-
return
60+
filenames = [filename]
6261

6362
for filename in filenames:
64-
entry = cache[filename]
63+
try:
64+
entry = cache[filename]
65+
except KeyError:
66+
continue
67+
6568
if len(entry) == 1:
6669
# lazy cache entry, leave it lazy.
6770
continue
Lines changed: 1 addition & 0 deletions
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)