Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple script that sends a message raises RuntimeError: Event loop is closed on Windows #863

Closed
evgfilim1 opened this issue Mar 15, 2022 · 4 comments
Labels
2.x Issue or PR for legacy 2.x version 3.x Issue or PR for stable 3.x version bug Something is wrong with the framework confirmed This issue is confirmed and requires action upstream Something not on our side

Comments

@evgfilim1
Copy link
Contributor

evgfilim1 commented Mar 15, 2022

Context

  • Operating System: Windows 10
  • Python Version: 3.9, 3.10
  • aiogram version: 2.19, 3.0.0b2
  • aiohttp version: 3.8.1

Expected Behavior

Process finishes gracefully

Current Behavior

Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000207916D4040>
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Failure Information (for bugs)

Steps to Reproduce

import asyncio

from aiogram import Bot

TOKEN = ""  # put your token here
CHAT_ID = 0  # put your user ID here


async def main():
    bot = Bot(TOKEN)
    await bot.send_message(CHAT_ID, "Hello there!")
    await bot.session.close()  # replace with `await bot.close()` on 2.x
    # await asyncio.sleep(0.1)


if __name__ == '__main__':
    asyncio.run(main())

If you uncomment sleep method, it works fine and finishes without traceback. I guess the problem is in aiohttp.
The message is delivered anyway, with or without sleep

@evgfilim1 evgfilim1 added bug Something is wrong with the framework help wanted Extra attention is needed 3.x Issue or PR for stable 3.x version confirmed This issue is confirmed and requires action labels Mar 15, 2022
@evgfilim1
Copy link
Contributor Author

evgfilim1 commented Mar 15, 2022

Related:

aio-libs/aiohttp#6635 (same problem)
https://docs.aiohttp.org/en/stable/client_advanced.html#graceful-shutdown (workaround is described in docs)
aio-libs/aiohttp#1925 (original issue, fix will be available in aiohttp>=4.0.0)

I will leave this issue open as an info for newcomers who face this issue also.

@evgfilim1 evgfilim1 added upstream Something not on our side and removed help wanted Extra attention is needed labels Mar 15, 2022
@evgfilim1 evgfilim1 changed the title Simply sending a message raises RuntimeError: Event loop is closed Simple script that sends a message raises RuntimeError: Event loop is closed Mar 15, 2022
@evgfilim1 evgfilim1 changed the title Simple script that sends a message raises RuntimeError: Event loop is closed Simple script that sends a message raises RuntimeError: Event loop is closed on Windows Mar 15, 2022
@evgfilim1 evgfilim1 removed the 3.x Issue or PR for stable 3.x version label Mar 15, 2022
@gabbhack
Copy link
Contributor

Also related: https://bugs.python.org/issue39232
Another workaround: encode/httpx#914 (comment)

@evgfilim1 evgfilim1 added 3.x Issue or PR for stable 3.x version 2.x Issue or PR for legacy 2.x version labels May 12, 2022
@DenisNagornuyk
Copy link

It's worked!

@JrooTJunior
Copy link
Member

Fixed in v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue or PR for legacy 2.x version 3.x Issue or PR for stable 3.x version bug Something is wrong with the framework confirmed This issue is confirmed and requires action upstream Something not on our side
Projects
None yet
Development

No branches or pull requests

4 participants