Skip to content

Event loop stalls even with an idle bot #2958

@mik111111

Description

@mik111111

Summary

The event loop stalls and results in "heartbeat blocked" warnings even with an entirely idle bot

Reproduction Steps

  1. Make a bot that does literally anything (including nothing at all)
  2. Run it
  3. See warnings like:
Shard ID None heartbeat blocked for more than 10 seconds.
Loop thread traceback (most recent call last):
  File "/tmp/test.py", line 13, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
  File "/usr/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/lib/python3.13/asyncio/base_events.py", line 712, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.13/asyncio/base_events.py", line 683, in run_forever
    self._run_once()
  File "/usr/lib/python3.13/asyncio/base_events.py", line 2012, in _run_once
    event_list = self._selector.select(timeout)
  File "/usr/lib/python3.13/selectors.py", line 452, in select
    fd_event_list = self._selector.poll(timeout, max_ev)

Minimal Reproducible Code

import discord, asyncio, logging

logging.basicConfig(
        format="%(asctime)s | %(levelname)s | %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
        level=logging.INFO)

bot = discord.Client()

async def main():
    await bot.start("TOKEN")

asyncio.run(main())

Expected Results

The bot runs correctly and without stall warnings

Actual Results

After about ~30 seconds the bot starts logging stall warnings every ~10 seconds.

Intents

None (it doesn't matter)

System Information

  • Python v3.13.7-final
  • py-cord v2.6.1-final
  • aiohttp v3.13.0
  • system info: Linux 6.17.2-arch1-1 #\1 SMP PREEMPT_DYNAMIC Sun, 12 Oct 2025 12:45:18 +0000

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

The issue seems to be specific to running the bot using discord.Client.start() in a preexisting event loop. When running using discord.Client.run() it works as expected.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions