[Python-checkins] gh-101766: Fix refleak for _BlockingOnManager resources (gh-101942)

corona10 webhook-mailer at python.org
Fri Feb 17 05:14:14 EST 2023


https://github.com/python/cpython/commit/775f8819e319127f9bfb046773b74bcc62c68b6a
commit: 775f8819e319127f9bfb046773b74bcc62c68b6a
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-02-17T19:14:07+09:00
summary:

gh-101766: Fix refleak for _BlockingOnManager resources (gh-101942)

files:
M Lib/importlib/_bootstrap.py

diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index bebe7e15cbce..1ef7b6adb044 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -85,6 +85,11 @@ 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):



More information about the Python-checkins mailing list