question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`wait_until_ready` does not always respect ready state

See original GitHub issue

Summary

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:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Rapptzcommented, Jun 12, 2022

This raises now.

2reactions
Rapptzcommented, Jun 12, 2022

I suppose in that case doing this should work fine:

async with bot:
    # load whatever
    await bot.start(...)

Should work for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bucket (Couchbase Java SDK 3.4.0 API)
waitUntilReady. Waits until the desired ClusterState is reached. This method will wait until either the cluster state is "online", or the timeout is...
Read more >
Readiness doesn't account for metadata.observedGeneration · Issue ...
Readiness and OpenshiftReadiness don't check, when using the status of resources, ... I.e. weird indeterminate states are just not "ready" (I don't care ......
Read more >
JavaScript SDK reference - LaunchDarkly docs
The behavior of waitUntilReady() is equivalent to the ready event. The promise resolves when the client receives its initial flag data. As with ......
Read more >
maximum recursion depth exceeded while calling a Python ...
Obviously, your waitUntilReady goes into infinite recursion, calling itself. You should change it to something like this: while not ...
Read more >
AMBA AXI and ACE Protocol Specification
AMBA SPECIFICATION TO YOU ON CONDITION THAT YOU ACCEPT ALL OF THE TERMS IN THIS LICENCE ... A source is not permitted to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found