You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
I am using aioredis in a FastAPI app.
I want to use the pubsub feature and setup subscriptions with callback functions.
Now my callback functions are async in nature and thus cooroutine instead of normal functions because inside them i need to await other coroutines (in my case sending content to a websocket entpoint). Unfortunately the code inside pubsub.run() (which calls get_message() which calls handle_message()) does not check if a callback might be an awaitable and should be awaited instead of called normally.
Instead the coroutine is never awaited, which raises a Warning and of course does not execute code inside the callback.
To Reproduce
setup a pubsub with a callback subscription. The callback is a async def ...
publish a message
Expected behavior
The awaitable callback function should be awaited instead of directly called.
Logs/tracebacks
..../lib/python3.10/site-packages/aioredis/client.py:4177: RuntimeWarning: coroutine 'websocket_endpoint.<locals>.send_messages' was never awaited
handler(message)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Python Version
$ python --versionPython 3.10.0
aioredis Version
$ python -m pip show aioredisVersion 2.0.0
Additional context
No response
Code of Conduct
I agree to follow the aio-libs Code of Conduct
The text was updated successfully, but these errors were encountered:
dnlwgnd
changed the title
subscription callback function cannot be coroutines
subscription callback function cannot be coroutine or awaitable
Dec 13, 2021
I can't recall from top of my head, but does order matter when it comes to callbacks? If so, then all passed in callbacks must convert to coroutines which is breaking change. If not, then we can use asyncio.iscoroutinefunction to decide whether to await or not (I believe awaiting does slow down code by a little if no I/O is being done and comparing to a sync function that also does no I/O).
If that didn't make sense, I'm just asking you to file a PR and I'll assign proper reviewers. Thanks.
@Andrew-Chen-Wang, maybe I didn't fully understand your concerns, but IMHO the order of the callbacks isn't guaranteed anyway as they are stored in a dict (unordered!) keyed by the channel. Maybe you could have a look and assign a reviewer?
Thanks!
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
I am using aioredis in a FastAPI app.
I want to use the pubsub feature and setup subscriptions with callback functions.
Now my callback functions are async in nature and thus cooroutine instead of normal functions because inside them i need to
await
other coroutines (in my case sending content to a websocket entpoint). Unfortunately the code insidepubsub.run()
(which callsget_message()
which callshandle_message()
) does not check if a callback might be an awaitable and should be awaited instead of called normally.Instead the coroutine is never awaited, which raises a Warning and of course does not execute code inside the callback.
To Reproduce
setup a pubsub with a callback subscription. The callback is a
async def ...
publish a message
Expected behavior
The awaitable callback function should be awaited instead of directly called.
Logs/tracebacks
Python Version
aioredis Version
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: