[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 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:06:26 +01:00 committed by GitHub
parent 6441d42f92
commit 9d0252ff2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -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