Skip to content

Commit

Permalink
pythongh-126775: make linecache.checkcache threadsafe and GC re-entre…
Browse files Browse the repository at this point in the history
…ncy safe (pythonGH-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]>
  • Loading branch information
3 people authored and miss-islington committed Dec 10, 2024
1 parent 6441d42 commit cfde364
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Lib/linecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe.

0 comments on commit cfde364

Please sign in to comment.