Skip to content

Commit

Permalink
asyncio.timeout doesn't support sync context manager protocol (#183)
Browse files Browse the repository at this point in the history
* asyncio.timeout doesn't support sync context manager protocol

* Fix tests

* Fix tests
  • Loading branch information
Pliner committed Mar 9, 2023
1 parent e4129ff commit 5200891
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test:
@python3 -m pytest -vv --rootdir tests .

pyenv:
echo aiopg-listen > .python-version && pyenv install -s 3.11.0 && pyenv virtualenv -f 3.11.0 aiopg-listen
echo aiopg-listen > .python-version && pyenv install -s 3.11.2 && pyenv virtualenv -f 3.11.2 aiopg-listen

pyenv-delete:
pyenv virtualenv-delete -f aiopg-listen
18 changes: 8 additions & 10 deletions aiopg_listen/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,14 @@ async def _process_notifications(
notification: NotificationOrTimeout

if notifications.empty():
try:
timeout_ctx = (
NO_TIMEOUT_CTX
if notification_timeout == NO_TIMEOUT
else timeout(notification_timeout)
)
with timeout_ctx: # type: ignore
notification = await notifications.get()
except asyncio.TimeoutError:
notification = Timeout(channel)
if notification_timeout == NO_TIMEOUT:
notification = await notifications.get()
else:
try:
async with timeout(notification_timeout):
notification = await notifications.get()
except asyncio.TimeoutError:
notification = Timeout(channel)
else:
while not notifications.empty():
notification = notifications.get_nowait()
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest==7.2.2
pytest-aiohttp==1.0.4
pytest-runner==6.0.0
isort==5.12.0
flake8==6.0.0
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool:pytest]
norecursedirs = .git .venv
python_files = tests.py test_*.py *_tests.py
asyncio_mode = auto

0 comments on commit 5200891

Please sign in to comment.