Skip to content

Commit

Permalink
[3.13] pythongh-126775: make linecache.checkcache threadsafe and GC r…
Browse files Browse the repository at this point in the history
…e-entrency safe (pythonGH-126776) (python#127778)

pythongh-126775: make linecache.checkcache threadsafe and GC re-entrency 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
4 people authored Dec 10, 2024
1 parent 6441d42 commit 9d0252f
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 9d0252f

Please sign in to comment.