Skip to content

[BUG] Possibility of Event loop is closed warning after Bot shutdown #2997

Closed as not planned
@harshil21

Description

@harshil21

While testing our code, we became aware that there could be a chance that we get an Event loop is closed error after shutting down the bot. This seems to only affect Windows and python versions 3.8+ and is related to ProactorEventLoop event loop policy on Windows.

MRE:

from telegram import Bot
import asyncio

async def bot_initialize():
    bot = Bot("TOKEN")
    await bot.initialize()

asyncio.run(bot_initialize())

The problem is most likely not with our library but with CPython itself, see python/cpython#83413 and encode/httpx#914.

A workaround would be to switch our default event loop policy to WindowsSelectorEventLoopPolicy, which is now what we do in tests. If multiple users are facing this problem frequently, we could consider switching.

If anybody is willing to dig into this further and figure out when/how/why exactly this error occurs, that would be great.

Python versions affected:

3.8, 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔗 windowsrelated technology: windows

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions