gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe (GH-126776)
(cherry picked from commit
2233c303e476496fc4c85a29a1429a7e4b1f707b)
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 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
--- /dev/null
+Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe.