The methods logout() and close() don't clean up the task Client._run_event()
I have seen the other entries and it appears the developer doesn't believe this is an issue with discord.py
None of my code appears in the stacktrace and appears to happen specifically due to
Client._run_event()
/usr/local/lib/python3.6/dist-packages/discord.py-1.0.0a1792+gdea3ba5-py3.6.egg/discord/client.py:218
This only happens in the rewrite.
I switched to the rewrite to use cogs and ran into this issue.
It prevents me from properly restarting my bot using a specific flag to make the bot kill itself and restart.
Using discord.py rewrite
discord.__version__
'1.0.0a'
import discord
import asyncio
from config import token
client = discord.Client()
@client.event
async def on_message(message):
if message.content.startswith("logout"):
await client.logout()
elif message.content.startswith("close"):
await client.close()
@client.event
async def on_ready():
print("Logged in as " + client.user.name + " /---/ " + str(client.user.id))
client.run(token)`
bot closes with no pending tasks being destroyed.
Task was destroyed but it is pending!
task:
Exception ignored in:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/discord.py-1.0.0a1792+gdea3ba5-py3.6.egg/discord/gateway.py", line 539, in close_connection
File "/home/kyle/.local/lib/python3.6/site-packages/websockets/protocol.py", line 855, in close_connection
File "/home/kyle/.local/lib/python3.6/site-packages/websockets/protocol.py", line 880, in wait_for_connection_lost
File "/usr/lib/python3.6/asyncio/tasks.py", line 342, in wait_for
File "/usr/lib/python3.6/asyncio/base_events.py", line 549, in call_later
File "/usr/lib/python3.6/asyncio/base_events.py", line 559, in call_at
File "/usr/lib/python3.6/asyncio/base_events.py", line 366, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task:
Edit(fixed formatting)
I did report this to Danny and he explained that it isn't a bug, so it isn't his problem. Here is context.
This is an issue with discord.py rewrite.
My code doesn't start the task. His code does.
Saying I'm responsible for the task is like saying I committed murder when someone paralyzes me, uses my hand to pull the trigger on a gun to kill someone without them touching the gun.
The only way to fix this is to edit his code.
Here's some code to use a restart command, although shutdown I don't have..
try:
await bot.close()
except:
pass
finally:
os.system("py -3 boot.py")
I use py -3 to boot my bot, if you use python bot.py then change it.
(Edit: I'm currently unaware of the situation but when I saw close I assumed restart so here ya go if you were, you just have to edit some stuff | Also use @client.command(pass_context=True))
@WhoTheOOF This is not relevant to this issue. Don't use os.system to restart your bot. The old interpreter stays open during this call, so over time you will stack endless interpreters, wasting memory.
If you need your bot to restart on exit, write something like a systemd service file so your errors are reported properly and your interpreter is allowed to exit gracefully.
@WhoTheOOF The restart I mentioned isn't really all that important.
I can easily do that by raising an exception and doing a systemctl restart bot
I do plan to integrate my bot with systemd for easy daemonizing
My main focus is trying to understand how this, which is clearly a bug with discord.py is being passed off from the developer as "not a bug"
This needs to be fixed. (important note: IN THE REWRITE)
It doesn't happen in the regular fork.
It only happens in the rewrite. 1.0.0a
@EvPayne Since you seem to be acting entitled and trying to pin me for something I'll give you a reply:
Regardless, I took the time to redesign and simplify the loop cleanup process but I haven't tested it in all platforms. Feel free to test it yourself.
Most helpful comment
@EvPayne Since you seem to be acting entitled and trying to pin me for something I'll give you a reply:
Regardless, I took the time to redesign and simplify the loop cleanup process but I haven't tested it in all platforms. Feel free to test it yourself.