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 authored and dvora-h committed Feb 25, 2024
1 parent e868a11 commit 87a4d8a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/examples/asyncio_examples.ipynb
Original file line number Diff line number Diff line change
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 87a4d8a

Please sign in to comment.