aio-libs / aiohttp-sse

Server-sent events support for aiohttp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Python 3.10: TypeError: sleep() got an unexpected keyword argument 'loop'

dtcooper opened this issue · comments

With Python 3.10, the loop argument to asyncio.sleep(...) was removed, so I end up with the following exception:

Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/test-9TtSrW0h-py3.10/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 430, in _handle_request
    resp = await request_handler(request)
  File "/root/.cache/pypoetry/virtualenvs/test-9TtSrW0h-py3.10/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/app/sse.py", line 97, in subscribe
    async with sse_response(request, headers={"Access-Control-Allow-Origin": "*"}) as resp:
  File "/root/.cache/pypoetry/virtualenvs/test-9TtSrW0h-py3.10/lib/python3.10/site-packages/aiohttp_sse/helpers.py", line 44, in __aexit__
    await self._obj.__aexit__(exc_type, exc, tb)
  File "/root/.cache/pypoetry/virtualenvs/test-9TtSrW0h-py3.10/lib/python3.10/site-packages/aiohttp_sse/__init__.py", line 152, in __aexit__
    await self.wait()
  File "/root/.cache/pypoetry/virtualenvs/test-9TtSrW0h-py3.10/lib/python3.10/site-packages/aiohttp_sse/__init__.py", line 107, in wait
    await self._ping_task
  File "/root/.cache/pypoetry/virtualenvs/test-9TtSrW0h-py3.10/lib/python3.10/site-packages/aiohttp_sse/__init__.py", line 144, in _ping
    await asyncio.sleep(self._ping_interval, loop=self._loop)
TypeError: sleep() got an unexpected keyword argument 'loop'

Which I've isolated to this line of code in aiohttp_sse/__init__.py:

    async def _ping(self):
        # periodically send ping to the browser. Any message that
        # starts with ":" colon ignored by a browser and could be used
        # as ping message.
        while True:
            await asyncio.sleep(self._ping_interval, loop=self._loop)
            await self.write(': ping{0}{0}'.format(self._sep).encode('utf-8'))

Suggested fix, remove loop=self._loop in the call above. Cheers and thanks!

Thanks for the report!

We need porting CI configuration from .travis.yml to github workflows first.

Would you help with it?
I'm pretty busy with other projects, sorry.

Sure! PR submitted.

We need porting CI configuration from .travis.yml to github workflows first.

We need the CI running first, which will probably catch this error (and any others).

If you want to try that out, you could use aiohttp-jinja2 or similar as a reference:
https://github.com/aio-libs/aiohttp-jinja2/blob/master/.github/workflows/ci.yml

I think that's a little out of my depth (never done it before). I think I'm only good for the quick fix (above). Cheers!