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

Lock not properly acquired when using asyncio.wait_for() #409

Open
marcmonfort opened this issue Apr 30, 2024 · 0 comments
Open

Lock not properly acquired when using asyncio.wait_for() #409

marcmonfort opened this issue Apr 30, 2024 · 0 comments

Comments

@marcmonfort
Copy link

When trying to use asyncio.wait_for() to add a timeout to acquire(), seems that it is not being properly acquired for the current task.

lock = RWLock()
try:
    await asyncio.wait_for(lock.writer_lock.acquire(), timeout=5)
    lock.writer_lock.release()
except asyncio.TimeoutError:
    pass

Traceback

Traceback (most recent call last):
  File "/home/marc/test/rwlock/venv/lib/python3.10/site-packages/aiorwlock/__init__.py", line 147, in _release
    self._owning.remove((me, lock_type))
ValueError: list.remove(x): x not in list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/marc/test/rwlock/test.py", line 61, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/marc/test/rwlock/test.py", line 52, in main
    await asyncio.gather(
  File "/home/marc/test/rwlock/test.py", line 26, in access_object
    lock.reader_lock.release()
  File "/home/marc/test/rwlock/venv/lib/python3.10/site-packages/aiorwlock/__init__.py", line 217, in release
    self._lock.release_read()
  File "/home/marc/test/rwlock/venv/lib/python3.10/site-packages/aiorwlock/__init__.py", line 136, in release_read
    self._release(self._RL)
  File "/home/marc/test/rwlock/venv/lib/python3.10/site-packages/aiorwlock/__init__.py", line 149, in _release
    raise RuntimeError('Cannot release an un-acquired lock')
RuntimeError: Cannot release an un-acquired lock

This same script using python built-in async lock works

lock = asyncio.Lock()
try:
    await asyncio.wait_for(lock.acquire(), timeout=5)
    lock.release()
except asyncio.TimeoutError:
    pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant