[Python-checkins] gh-101766: Fix refleak for _BlockingOnManager resources from test suite level (gh-101988)

corona10 webhook-mailer at python.org
Fri Feb 17 10:18:56 EST 2023


https://github.com/python/cpython/commit/f482ade4c7887c49dfd8bba3be76f839e562608d
commit: f482ade4c7887c49dfd8bba3be76f839e562608d
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-02-18T00:18:47+09:00
summary:

gh-101766: Fix refleak for _BlockingOnManager resources from test suite level (gh-101988)

files:
M Lib/importlib/_bootstrap.py
M Lib/test/test_importlib/test_locks.py

diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 1ef7b6adb044..bebe7e15cbce 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):
diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py
index 56d73c496e6b..ba9cf51c261d 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()}
 



More information about the Python-checkins mailing list