I am trying to integrate asyncpg with discord.py, however I ran into one very anoyying issue.
Whenever I try to stop the bot using ^C, I get spammed with a ton of errors. This is just bothersome as when I'm trying to debug something I often lose the original error.
Here is my code:
loop = asyncio.get_event_loop()
async def connection_init(conn):
await conn.execute("SET CLIENT_ENCODING to 'utf-8';")
conn.client = client
try:
client.pool = loop.run_until_complete(asyncpg.create_pool(
host=os.environ.get("postgres_host"),
database=os.environ.get("postgres_database"),
user=os.environ.get("postgres_user"),
password=os.environ.get("postgres_password"),
connection_class=dbutils.DBUtils,
init=connection_init
))
print('PostgreSQL connection successful')
except Exception as e:
print(e)
# the bot basically cannot function without database
print('PostgreSQL connection failed- aborting')
exit()
client.run(os.environ.get("main"))
Here are the errors that floods my terminal. It's the same error however it pops up like 20 times.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x033DF148>
Traceback (most recent call last):
File "C:UserszghanAppDataLocalProgramsPythonPython38-32libasyncioproactor_events.py", line 116, in __del__
File "C:UserszghanAppDataLocalProgramsPythonPython38-32libasyncioproactor_events.py", line 108, in close
File "C:UserszghanAppDataLocalProgramsPythonPython38-32libasyncioase_events.py", line 719, in call_soon
File "C:UserszghanAppDataLocalProgramsPythonPython38-32libasyncioase_events.py", line 508, in _check_closed
RuntimeError: Event loop is closed
question from:
https://stackoverflow.com/questions/65838092/spammed-with-errors-from-asyncpg-when-discord-bot-is-turned-off 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…