Skip to content

Commit

Permalink
Tolerate already deleted lockfiles when releasing the lock
Browse files Browse the repository at this point in the history
This should prevent issues like
#232 from appearing
  • Loading branch information
dcermak committed Oct 25, 2024
1 parent 1e19e12 commit a06a24b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pytest_container/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,14 @@ def launch_container(self) -> None:
def release_lock() -> None:
_logger.debug("Releasing lock %s", lock.lock_file)
lock.release()
os.unlink(lock.lock_file)
# we're fine with another process/thread having deleted the
# lockfile, as long as the locking was thread safe
try:
# no we can't use Path.unlink(missing_ok=True) here, as the kw
# argument is not present in Python < 3.8
os.unlink(lock.lock_file)
except FileNotFoundError:
pass

Check warning on line 1102 in pytest_container/container.py

View check run for this annotation

Codecov / codecov/patch

pytest_container/container.py#L1101-L1102

Added lines #L1101 - L1102 were not covered by tests

# Container preparation can fail, but then we would never release the
# lock as release_lock is not yet in self._stack. However, we do not
Expand Down

0 comments on commit a06a24b

Please sign in to comment.