Skip to content

Commit

Permalink
Fix inner/outer for write
Browse files Browse the repository at this point in the history
  • Loading branch information
Yard1 authored Nov 23, 2024
1 parent e0e4911 commit c669bdc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/filelock/read_write/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,16 @@ def acquire(
lock.release()
"""
with self._outer_lock:
self._inner_lock.acquire()
return AcquireReturnProxy(lock=self)
if self.read_write_mode == ReadWriteMode.READ:
with self._outer_lock:
self._inner_lock.acquire()
return AcquireReturnProxy(lock=self)
elif self.read_write_mode == ReadWriteMode.WRITE:
self._outer_lock.acquire()
with self._inner_lock:
# Just acquire.
pass
return AcquireReturnProxy(lock=self)

def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002
"""
Expand All @@ -217,7 +224,10 @@ def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002
:param force: If true, the lock counter is ignored and the lock is released in every case/
"""
self._inner_lock.release(force=force)
if self.read_write_mode == ReadWriteMode.READ:
self._inner_lock.release(force=force)
elif self.read_write_mode == ReadWriteMode.WRITE:
self._outer_lock.release(force=force)

def __enter__(self) -> Self:
"""
Expand Down

0 comments on commit c669bdc

Please sign in to comment.