Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor to not do too much in ReentrantFileLock.__del__ #2213

Merged
merged 1 commit into from
Oct 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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