Closed as not planned
Description
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