python-3.x - Shard ID %s 心跳被阻塞超过 10s 秒。问题
问题描述
嗨,我遇到了一个问题,返回一个很长的错误Shard ID %s heartbeat blocked for more than 10s seconds.
我最初认为我可能会因为数据库返回任何信息而发生这种情况,因为它是空的。我试图通过检查 None 并返回它来防止错误,但错误仍然存在。
> Message: 'Shard ID %s heartbeat blocked for more than %s seconds.\nLoop thread traceback (most recent
call last):\n File "/app/run.py", line 270, in <module>\n bot.run(token)\n File
"/app/.jack/python/lib/python3.9/site-packages/discord/client.py", line 713, in run\n
loop.run_forever()\n File "/app/.jack/python/lib/python3.9/asyncio/base_events.py", line 596, in
run_forever\n self._run_once()\n File "/app/.jack/python/lib/python3.9/asyncio/base_events.py",
line 1890, in _run_once\n handle._run()\n File
"/app/.jack/python/lib/python3.9/asyncio/events.py", line 80, in _run\n
self._context.run(self._callback, *self._args)\n File "/app/.jack/python/lib/python3.9/site-
packages/discord/client.py", line 343, in _run_event\n await coro(*args, **kwargs)\n File
"/app/cogs/mods.py", line 339, in mute_check\n cursor.execute("SELECT username FROM blacklist
WHERE username=%s", (user.id, ))\n
> : Arguments: (None, 10)
这是我正在使用的内容:
@tasks.loop(seconds=60)
async def mute_check(self):
await self.bot.wait_until_ready()
self.ready = True
guild = self.bot.get_guild(ID)
for member in guild.members:
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cursor = conn.cursor()
# Changed the query so that NULLs (which will be cast as None) are not returned
cursor.execute("SELECT time FROM blacklist WHERE username=%s AND time IS NOT NULL", (member.id, ))
# no index needed, multiple stamps are returned
results = cursor.fetchall()
for result in results:
if result is None:
return
# first and only returned element
timestamp = result[0]
restricted_role = get(guild.roles, name="Restricted")
datestamp = datetime.now()
datetimestring = str(datestamp.now().strftime("%Y%m%d%H%M%S"))
dateonlystring = timestamp.strftime("%Y%m%d%H%M%S")
if (datetimestring > dateonlystring):
await member.remove_roles(restricted_role, reason='Restricted role removed (auto timer).')
cursor.close()
conn.close()
帮助将不胜感激。
解决方案
推荐阅读
- google-apps-script - 使用 Apps 脚本将文件从一个文件夹复制到云端硬盘上的另一个文件夹
- python - pipenv 的问题
- javascript - Typescript 来自另一个 const 数组的项目数组(来自官方初学者教程)
- python - 游戏 | 每次我尝试运行它时它都会显示一个黑屏然后崩溃,即使它以前工作过
- javascript - 如何使用react js替换对象数组中的修改对象
- forms - 如何知道父表单中子表单的关闭事件
- arrays - php 与此数组编号 array(11) [0] => 1
- end-to-end-encryption - 如何在 EE2E 中读取来自另一台设备的消息
- linux - 遍历数组以在 Bash 中搜索多个元素
- perl - Perl (MQSeries):如何使用 TLS 连接到 WMQ 的通道(“相同的代码”在 C++ 中工作)