-
-
Notifications
You must be signed in to change notification settings - Fork 476
refactor: Update Client.run
to have a better async I/O usage
#2645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Dorukyum <[email protected]> Signed-off-by: DA344 <[email protected]>
Co-authored-by: Dorukyum <[email protected]> Signed-off-by: DA344 <[email protected]>
Applied all the changes Dorukyum requested. Before merging, I would like some feedback on this discussion message |
i tested this pr on my prod bot for some hours and nothing to issue to signal |
Signed-off-by: DA344 <[email protected]>
I've done some testing and it has been working as expected. Can this pr get any review more/merge ? |
This is required if we ever want py 3.14 support, see my pr about that |
Not just for 3.14 support, but to fix all asyncio related issues that can be presented in any version due to how the AbstractEventLoop is currently handled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm as long as that MISSING
comment is resolved in some way or another, nice pr
Could be neat if we could get this merged for 2.7 |
Also please @DA-344 fix conflicts (sry 😅) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to test something
@DA-344 The test code below crashes, can you take a look ? I think it has to do with Line 249 in 2ae01b7
Test Codeimport os
import discord
import asyncio
import logging
from dotenv import load_dotenv
logging.basicConfig(level=logging.INFO)
load_dotenv()
bot = discord.Bot(intents=discord.Intents.all())
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} ({bot.user.id})")
options = [
"Option 1",
"Option 2",
"Option 3",
"Option 4",
]
async def my_autocomplete(ctx: discord.AutocompleteContext):
"""Autocomplete function for the command"""
query = ctx.value.lower()
return [option for option in options if query in option.lower()]
class MyCog(discord.Cog):
"""Example cog for the bot"""
def __init__(self, bot: discord.Bot):
self.bot: discord.Bot = bot
@discord.command(name="hello")
@discord.option(
name="option",
description="An example option",
required=True,
autocomplete=my_autocomplete,
)
async def hello(self, ctx: discord.ApplicationContext, option: str):
await ctx.respond(f"Hello! You selected: {option}")
async def load_cogs():
bot.add_cog(MyCog(bot))
async def main():
await load_cogs()
try:
await bot.start(os.getenv("TOKEN_3", ""))
except KeyboardInterrupt:
await bot.close()
if __name__ == "__main__":
asyncio.run(main()) |
Yup, I forgot to update that to use |
Summary
This PR refactors the
Client.run
logic to fix problems involving asyncio due to how the library used the loop:Needs testing
Exception
Information
examples, ...).
Checklist
type: ignore
comments were used, a comment is also left explaining why.