Skip to content

Commit

Permalink
docs: Add timeout parameter for get_message example (#3129)
Browse files Browse the repository at this point in the history
The `get_message()` method in asyncio PubSub has a `timeout` argument that defaults to 0.0, causing it to immediately return. This can cause high CPU usage with the given code example and should not be recommended. By setting `timeout=None`, it works with much more efficient resource usage.
  • Loading branch information
hongqn committed Feb 5, 2024
1 parent 7df57e5 commit 6240ea1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/examples/asyncio_examples.ipynb
Expand Up @@ -201,7 +201,7 @@
"\n",
"async def reader(channel: redis.client.PubSub):\n",
" while True:\n",
" message = await channel.get_message(ignore_subscribe_messages=True)\n",
" message = await channel.get_message(ignore_subscribe_messages=True, timeout=None)\n",
" if message is not None:\n",
" print(f\"(Reader) Message Received: {message}\")\n",
" if message[\"data\"].decode() == STOPWORD:\n",
Expand Down Expand Up @@ -264,7 +264,7 @@
"\n",
"async def reader(channel: redis.client.PubSub):\n",
" while True:\n",
" message = await channel.get_message(ignore_subscribe_messages=True)\n",
" message = await channel.get_message(ignore_subscribe_messages=True, timeout=None)\n",
" if message is not None:\n",
" print(f\"(Reader) Message Received: {message}\")\n",
" if message[\"data\"].decode() == STOPWORD:\n",
Expand Down

0 comments on commit 6240ea1

Please sign in to comment.