From b38b4246a7a2f49d470694dc545d50ba7c4b587e Mon Sep 17 00:00:00 2001 From: mattip Date: Wed, 13 Oct 2021 18:50:29 +0300 Subject: [PATCH] refactor to not do too much in __del__ --- 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):