From dee2dd74044f5c3bc4a0c35e1fc311e8aefcde59 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 13 Nov 2024 10:42:48 +0000 Subject: [PATCH 1/4] gh-126775: make linecache.checkcache threadsafe and GC re-entrency safe --- Lib/linecache.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/linecache.py b/Lib/linecache.py index 4b38a0464d8747..ea48c4a5a1bd39 100644 --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -49,14 +49,16 @@ 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] + 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 From 18034010bf77273ce12f8dc5bbba7123265b0e5e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:44:30 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst 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..fb46412adebfd1 --- /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` threadsafe and GC re-entrency safe From a2399bad4037fce30a5bc7682e171f7c379b4711 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 19 Nov 2024 08:23:52 +0000 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartosz Sławecki --- .../next/Library/2024-11-13-10-44-25.gh-issue-126775.a3ubjh.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index fb46412adebfd1..429fc2aa17bd42 100644 --- 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 @@ -1 +1 @@ -make :func:`linecache.checkcache` threadsafe and GC re-entrency safe +Make :func:`linecache.checkcache` thread safe and GC re-entrancy safe. From ba0cc8d8ed27d372b450c8144a8d9e39a494f046 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 4 Dec 2024 09:52:40 +0000 Subject: [PATCH 4/4] Update Lib/linecache.py --- Lib/linecache.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/linecache.py b/Lib/linecache.py index ea48c4a5a1bd39..8ba2df73d5a8fb 100644 --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -49,6 +49,7 @@ def checkcache(filename=None): (This is not checked upon each call!)""" if filename is None: + # get keys atomically filenames = cache.copy().keys() else: filenames = [filename]