`wait_until_ready` does not always respect ready state
See original GitHub issueSummary
wait_until_ready
does not wait if used too early, despite the cache not being ready.
Reproduction Steps
Using wait_until_ready
too early will not actually wait, despite Client.is_ready()
returning False
.
The reproduction example shown here is very contrived, but a more real world scenario is a call to load_extension
for a cog that contains a background task, where the task is started in the setup hook, and that task blocks with a wait_until_ready
before kicking off.
With the current version, sometimes a task will start executing despite the client cache not being ready, if the task is started directly from the cog’s setup
function.
Minimal Reproducible Code
import asyncio
import logging
from discord.client import Client
from discord import Intents
logging.basicConfig(level=logging.INFO)
client = Client(intents=Intents())
async def main():
print(f"Ready? - {client.is_ready()}") # False
await client.wait_until_ready() # Does not wait
await client.start("token")
asyncio.run(main())
Expected Results
In this contrived example, the client should not start, as we’ll wait indefinitely for the cache to be ready.
Actual Results
The client starts as normal, despite the explicit call to wait for the cache to be ready before starting (which will never happen as we haven’t logged in).
Intents
Intents()
System Information
- Python v3.9.10-final
- discord.py v2.0.0-alpha
- discord.py pkg_resources: v2.0.0a4341+g3cb90199
- aiohttp v3.8.1
- system info: Darwin 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
It’s possible to workaround this by starting the task via setup_hook
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
This raises now.
I suppose in that case doing this should work fine:
Should work for you.