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):