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
In redis-py's asyncio pubsub get_message() function, the timeout kwarg defaults to 0, which means the function by default returns immediately if there is no message available. So if one were to blindly follow the example code, which essentially amounts to:
whileTrue:
message=awaitpubsub.get_message()
ifmessage:
# Deal with message...
They will find that the thread running this example code is pegged at 100% usage, constantly burning through that tight loop. To get the behaviour that a sane person would expect (yielding to the event loop until the message is available), they need to explicitly set timeout=None.
This is a terrible default value which resulted in me spending an entire afternoon trying to figure out why my server was pinned at 100% CPU usage, even though there were zero messages going through the pubsub channel. I have since changed my code to use timeout=None, but I really think this should be the default, especially when using the async version of the client (I have not checked to see if the same footgun applies to the synchronous API).
The text was updated successfully, but these errors were encountered:
I guess at this point changing the default value would be a breaking change for many users. At the very least, can we add some big bold warnings to the documentation?
Version: redis-py 5.0.3, redis 7.0.12
Platform: Python 3.12 on Linux
Description:
In
redis-py
's asyncio pubsubget_message()
function, thetimeout
kwarg defaults to 0, which means the function by default returns immediately if there is no message available. So if one were to blindly follow the example code, which essentially amounts to:They will find that the thread running this example code is pegged at 100% usage, constantly burning through that tight loop. To get the behaviour that a sane person would expect (yielding to the event loop until the message is available), they need to explicitly set
timeout=None
.This is a terrible default value which resulted in me spending an entire afternoon trying to figure out why my server was pinned at 100% CPU usage, even though there were zero messages going through the pubsub channel. I have since changed my code to use
timeout=None
, but I really think this should be the default, especially when using the async version of the client (I have not checked to see if the same footgun applies to the synchronous API).The text was updated successfully, but these errors were encountered: