Skip to content

Commit

Permalink
refactor to not do too much in ReentrantFileLock.__del__ (#2213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip authored Oct 23, 2021
1 parent 6633e85 commit c77c6bc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/virtualenv/util/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c77c6bc

Please sign in to comment.