From: Dong-hee Na Date: Fri, 17 Feb 2023 10:14:07 +0000 (+0900) Subject: gh-101766: Fix refleak for _BlockingOnManager resources (gh-101942) X-Git-Tag: v3.12.0a6~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=775f8819e319127f9bfb046773b74bcc62c68b6a;p=thirdparty%2FPython%2Fcpython.git gh-101766: Fix refleak for _BlockingOnManager resources (gh-101942) --- 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 @@ class _BlockingOnManager: 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):