https://github.com/python/cpython/commit/e881dd1c468beafd81d20be2e66a5fdd49cb3402 commit: e881dd1c468beafd81d20be2e66a5fdd49cb3402 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: cfbolz <[email protected]> date: 2024-12-10T08:02:22Z summary:
[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 2233c303e476496fc4c85a29a1429a7e4b1f707b) Co-authored-by: Thomas Grainger <[email protected]> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Bartosz Sławecki <[email protected]> files: A Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst M Lib/linecache.py diff --git a/Lib/linecache.py b/Lib/linecache.py index 248cba93874c47..b6453fe2f31179 100644 --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -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 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 00000000000000..429fc2aa17bd42 --- /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. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
