From 707db416715eb0b40ca15a6b7017a2ec608678fd Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 17 Feb 2023 11:51:59 +0000 Subject: [PATCH 1/2] Revert "gh-101766: Fix refleak for _BlockingOnManager resources (gh-101942)" This reverts commit 775f8819e319127f9bfb046773b74bcc62c68b6a. --- Lib/importlib/_bootstrap.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 1ef7b6adb04434..bebe7e15cbce67 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -85,11 +85,6 @@ 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] - del self.blocked_on class _DeadlockError(RuntimeError): From a85f0e6b4dac9b5b97bdf77a07c944aeb333f8d2 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 17 Feb 2023 13:13:01 +0000 Subject: [PATCH 2/2] Fix refleak at test suite level --- Lib/test/test_importlib/test_locks.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py index 56d73c496e6bbb..ba9cf51c261d52 100644 --- a/Lib/test/test_importlib/test_locks.py +++ b/Lib/test/test_importlib/test_locks.py @@ -33,6 +33,11 @@ class ModuleLockAsRLockTests: test_repr = None test_locked_repr = None + def tearDown(self): + for splitinit in init.values(): + splitinit._bootstrap._blocking_on.clear() + + LOCK_TYPES = {kind: splitinit._bootstrap._ModuleLock for kind, splitinit in init.items()}