-
-
Notifications
You must be signed in to change notification settings - Fork 596
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
AsyncServer.start_background_task fails on aiohttp 3.8 #881
Comments
Have you considered that this might be your own issue? You are launching an async function before the web framework, which controls the async loop. More than likely aiohttp is creating their own loop, so the default loop used when you started the task goes away and that causes the message that you are seeing. |
Thanks for the quick reply! That might explain why it's not working, however there are still three issues:
|
Yes, I agree, that example needs to be updated so that it is compatible with the newer aiohttp. I'll look into that. |
This is actually the change in aiohttp that relates to this: aio-libs/aiohttp#5572 |
The solution is to use an application factory function to start the background task: async def init_app():
sio.start_background_task(background_task)
return app
if __name__ == '__main__':
web.run_app(init_app()) |
Thanks! I verified that this solution works with |
When running
AsyncServer.start_background_task
onaiohttp
3.8
(both3.8.0
or3.8.1
), the server fails with aRuntimeWarning: coroutine 'background_task' was never awaited
error, but the same code works fine on3.7.4
.This is a minimal reproducer based on the example in the repo:
After installing
aiohttp
3.7.4
withpip install aiohttp==3.7.4
, the server works and the output is:After installing
aiohttp
3.8.1
withpip install aiohttp==3.8.1
, the server fails with the output:I'm not sure if this is an issue with
python-socketio
or a bug inaiohttp
itself. Regardless, I thought it would be useful to report it here since otherpython-socketio
users might run in the same problem.aiohttp
3.8
might have introduced a backward incompatible change that requires an update topython-socketio
. If you can verify that this is indeed an issue withaiohttp
, and possibly even figure out the cause of the problem, we can then report it upstream.This was tested with
python-socketio
5.5.2
on Python 3.9.10.The text was updated successfully, but these errors were encountered: