python - aiomysql/discord py - 一个开放的流对象正在被垃圾收集;显式调用“stream.close()”
问题描述
我有一个非常奇怪的问题。目前我尝试打开与 MySQL 的数据库连接,如果用户写了一条消息,则获取一些东西并关闭它(使用库 aiomysql)。所以一切正常,除了关闭连接,我不明白为什么。因为我使用这种方式来关闭我所有其他不和谐机器人中的连接并且它工作完美,但不是在这里。
我的代码:
@commands.Cog.listener("on_message")
async def on_message(self, message):
###### React on AFK User ping ######
mydb1 = await getConnection1()
mycursor = await mydb1.cursor()
if len(message.mentions) >= 1 and message.author not in message.mentions and not message.author.bot:
await mycursor.execute("SELECT * FROM afk WHERE memberid = %s", (int(message.mentions[0].id),))
myresult = await mycursor.fetchone()
if myresult and ".afk" not in message.content:
..
await mycursor.execute("SELECT * FROM afk WHERE memberid = %s", (int(message.author.id),))
myresult1 = await mycursor.fetchone()
# React on AFK User writes
if myresult1 and ".afk" not in message.content:
..
print(1)
await mycursor.close()
mydb1.close()
print(2)
我得到错误An open stream object is being garbage collected; call "stream.close()" explicitly.
- 为什么?最后一个连接关闭。我正在使用aiomysql
.
解决方案
推荐阅读
- windows - MDT Web 服务 - 完成此操作所需的数据尚不可用。(-2147483638 0x8000000A)
- javascript - Cucumber JS:当我将表和另一个变量传递给步骤 def 时,出现“table.rows()”不是有效函数”错误
- c++ - 将自己的类的实例传递给另一个
- php - 无法发布 /get.php
- python - django settings.py 不会读取单元测试的环境变量
- java - Android Studio 向 Firebase 发送数据,但 Firebase 数据库中没有保存数据
- docker - 无法在 Kubernetes 部署中查询 Kafka
- xml - 如何在 Google 表格中使用 XPath 从 Kick Starter 抓取文本
- javascript - 如何在向下滚动时更改伪选择器的背景颜色
- javascript - 在 Bootstrap Modal 中动态设置 Select 列表的 'selected' 属性