Skip to content

Commit

Permalink
Add a note about acquiring/releasing by the same task
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Nov 25, 2024
1 parent 1577030 commit 98cee7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ frequently searched is an ideal candidate for the use of a read-write lock.
However, if updates become frequent then the data spends most of its time
being exclusively locked and there is little, if any increase in concurrency.

**Note:** a task that *acquires* the lock should be used for *releasing* it.
Locking from one task and releasing from another one generates ``RuntimeError``.


Implementation is almost direct port from this patch_.

Expand Down
4 changes: 2 additions & 2 deletions aiorwlock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def _release(self, lock_type: int) -> None:

try:
self._owning.remove((me, lock_type))
except ValueError:
raise RuntimeError('Cannot release an un-acquired lock')
except ValueError as exc:
raise RuntimeError('Cannot release an un-acquired lock') from exc
if lock_type == self._RL:
self._r_state -= 1
else:
Expand Down

0 comments on commit 98cee7d

Please sign in to comment.