[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 2233c303e4)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bartosz Sławecki <bartoszpiotrslawecki@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-12-10 09:02:22 +01:00 committed by GitHub
parent fa935225a4
commit e881dd1c46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -54,14 +54,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

View file

@ -0,0 +1 @@
Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe.