Skip to content

gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe #126776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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.
Loading