diff options
author | Thomas Grainger <tagrain@gmail.com> | 2024-12-10 07:40:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 07:40:54 (GMT) |
commit | 2233c303e476496fc4c85a29a1429a7e4b1f707b (patch) | |
tree | 19c1d1fa402c289b0380099bb7568e550828b157 | |
parent | 3983527c3a6b389e373a233e514919555853ccb3 (diff) | |
download | cpython-2233c303e476496fc4c85a29a1429a7e4b1f707b.zip cpython-2233c303e476496fc4c85a29a1429a7e4b1f707b.tar.gz cpython-2233c303e476496fc4c85a29a1429a7e4b1f707b.tar.bz2 |
gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe (#126776)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bartosz Sławecki <bartoszpiotrslawecki@gmail.com>
-rw-r--r-- | Lib/linecache.py | 13 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst | 1 |
2 files changed, 9 insertions, 5 deletions
diff --git a/Lib/linecache.py b/Lib/linecache.py index 4b38a04..8ba2df7 100644 --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -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 diff --git a/Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst b/Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst new file mode 100644 index 0000000..429fc2a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst @@ -0,0 +1 @@ +Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe. |