From c77c6bc30edde2885091ad0945a093638ecbf45a Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Sat, 23 Oct 2021 13:11:41 +0300 Subject: [PATCH] refactor to not do too much in ReentrantFileLock.__del__ (#2213) --- src/virtualenv/util/lock.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/util/lock.py b/src/virtualenv/util/lock.py index 739dc5af8..e141aafae 100644 --- a/src/virtualenv/util/lock.py +++ b/src/virtualenv/util/lock.py @@ -90,8 +90,8 @@ def _create_lock(self, name=""): @staticmethod def _del_lock(lock): - with _store_lock: - if lock is not None: + if lock is not None: + with _store_lock: with lock.thread_safe: if lock.count == 0: _lock_store.pop(lock.lock_file, None) @@ -105,6 +105,8 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): self._release(self._lock) + self._del_lock(self._lock) + self._lock = None def _lock_file(self, lock, no_block=False): # multiple processes might be trying to get a first lock... so we cannot check if this directory exist without @@ -138,6 +140,7 @@ def lock_for_key(self, name, no_block=False): self._release(lock) finally: self._del_lock(lock) + lock = None @contextmanager def non_reentrant_lock_for_key(self, name):