首页 > 解决方案 > 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()

帮助将不胜感激。

标签: python-3.xpostgresqldiscord.py

解决方案


推荐阅读