From 65c845feda2e5edb7bfccce41ecb1cc47a2dbeb3 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 14 Feb 2023 22:47:24 +0000 Subject: [PATCH 1/2] gh-101766: Fix refleak for _BlockingOnManager resources --- Lib/importlib/_bootstrap.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index bebe7e15cbce67..8a8031bc54e527 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -85,6 +85,10 @@ def __enter__(self): def __exit__(self, *args, **kwargs): """Remove self.lock from this thread's _blocking_on list.""" self.blocked_on.remove(self.lock) + if len(self.blocked_on) == 0: + # gh-101766: glboal cache should be cleaned-up + # if there is no more _blocking_on for this thread. + del _blocking_on[self.thread_id] class _DeadlockError(RuntimeError): From 79fd697175682f153504534aa2320a1ebf3fd8fa Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 17 Feb 2023 07:26:55 +0900 Subject: [PATCH 2/2] Update Lib/importlib/_bootstrap.py Co-authored-by: Eric Snow --- Lib/importlib/_bootstrap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 8a8031bc54e527..1ef7b6adb04434 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -89,6 +89,7 @@ def __exit__(self, *args, **kwargs): # gh-101766: glboal cache should be cleaned-up # if there is no more _blocking_on for this thread. del _blocking_on[self.thread_id] + del self.blocked_on class _DeadlockError(RuntimeError):