Skip to content
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

"asyncio.run() cannot be called from a running event loop") #9806

Closed
3 tasks done
itsXactlY opened this issue Apr 26, 2024 · 3 comments
Closed
3 tasks done

"asyncio.run() cannot be called from a running event loop") #9806

itsXactlY opened this issue Apr 26, 2024 · 3 comments
Labels
invalid This is not right.

Comments

@itsXactlY
Copy link

itsXactlY commented Apr 26, 2024

Summary

"asyncio.run() cannot be called from a running event loop")"

Reproduction Steps

Debugging in Interactive Shell.

client.run('REDACTEDTOKEN') ->

import discord
import os
import asyncio
from collections import deque
import ollama
import threading

intents = discord.Intents.all()
intents.members = True

client = discord.Client(intents=intents, heartbeat_timeout=60)

@client.event
async def on_ready():
    print(f'Logged in as {client.user}')
    # Start the queue processing task
    await asyncio.create_task(process_queue())
    
client.run('REDACTED_TOKEN')

Minimal Reproducible Code

RuntimeError                              Traceback (most recent call last)
File /home/alca/projects/discord_ai.py:105
    102     # Start the queue processing task
    103     await asyncio.create_task(process_queue())
--> 105 client.run('')

File ~/projects/.bt/lib/python3.11/site-packages/discord/client.py:860, in Client.run(self, token, reconnect, log_handler, log_formatter, log_level, root_logger)
    852     utils.setup_logging(
    853         handler=log_handler,
    854         formatter=log_formatter,
    855         level=log_level,
    856         root=root_logger,
    857     )
    859 try:
--> 860     asyncio.run(runner())
    861 except KeyboardInterrupt:
    862     # nothing to do here
    863     # `asyncio.run` handles the loop cleanup
    864     # and `self.start` closes all sockets and the HTTPClient instance.
    865     return

File /usr/lib/python3.11/asyncio/runners.py:186, in run(main, debug)
    161 """Execute the coroutine and return the result.
    162 
...
    187         "asyncio.run() cannot be called from a running event loop")
    189 with Runner(debug=debug) as runner:
    190     return runner.run(main)

RuntimeError: asyncio.run() cannot be called from a running event loop

Expected Results

Run the Bot, what a dumb timewasting question.

Actual Results

Stop annoying questions, ffs.

Intents

... ALL!

System Information

Python v3.11.7-final

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

No response

@itsXactlY itsXactlY added the unconfirmed bug A bug report that needs triaging label Apr 26, 2024
@mishalhossin
Copy link

Dude..

@itsXactlY
Copy link
Author

itsXactlY commented Apr 26, 2024

And, after sending my Report here,..

Exception has occurred: ConnectionClosed
Shard ID None WebSocket closed with 4004
discord.gateway.WebSocketClosure: 

During handling of the above exception, another exception occurred:

  File "/home/alca/projects/discord_ai.py", line 105, in <module>
    client.run('REDACTED_TOKEN')
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4004

@mikeshardmind
Copy link
Contributor

Error tells you everything relevent, and is an asyncio error, not a discord.py one.

see docs for client.run which has a warning about this, docs for client.start which provides a way to run in an existing event loop, and the advanced startup example in the repo

@Rapptz Rapptz added invalid This is not right. and removed unconfirmed bug A bug report that needs triaging labels May 6, 2024
@Rapptz Rapptz closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not right.
Projects
None yet
Development

No branches or pull requests

4 participants