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

Shutdown Event is skipped on bot closing. #1410

Open
2 tasks done
Dizyreal opened this issue Feb 9, 2024 · 2 comments
Open
2 tasks done

Shutdown Event is skipped on bot closing. #1410

Dizyreal opened this issue Feb 9, 2024 · 2 comments
Labels
docs Something is missing in docs

Comments

@Dizyreal
Copy link

Dizyreal commented Feb 9, 2024

Checklist

  • I am sure the error is coming from aiogram code
  • I have searched in the issue tracker for similar bug reports, including closed ones

Operating system

Windows 11 Pro 22H2

Python version

Python 3.11.6

aiogram version

3.3.0

Expected behavior

Shutdown Event in Dispatcher should be fired, so all the registered functions should be called.

Current behavior

Shutdown Event in Dispatcher is ignored. Registered functions aren't getting called on bot closing.

Steps to reproduce

  1. Used basic API templates to make the Bot.
  2. Shutdown event in dispatcher is ignored in the following code.

Code example

import asyncio
import logging
from aiogram import Dispatcher, Bot, Router, types, F
from aiogram.filters.command import Command

# constants
BOT_TOKEN = "bla-bla"
OWNER_ID = "bla-bla"

# setup configs
logging.basicConfig(level=logging.INFO)

async def on_startup(bot: Bot):
    await bot.send_message(OWNER_ID, "Bot launched!")

async def on_shutdown(bot: Bot):
    await bot.send_message(OWNER_ID, "Bot closed!")
    
async def start():
    dp = Dispatcher()
    dp.shutdown.register(on_shutdown)
    dp.startup.register(on_startup)
    bot = Bot(token=BOT_TOKEN)
    
    try:
        await dp.start_polling(bot)
    finally:
        await bot.session.close()

if __name__ == "__main__":
    asyncio.run(start())

Logs

No response

Additional information

There is no logs about closing. Event is just skipped.

@Dizyreal Dizyreal added the bug Something is wrong with the framework label Feb 9, 2024
@Olegt0rr Olegt0rr added docs Something is missing in docs and removed bug Something is wrong with the framework labels Feb 10, 2024
@Olegt0rr
Copy link
Contributor

Olegt0rr commented Feb 10, 2024

Signals are not supported by Windows, so you need to stop polling explicitly by await dp.stop_polling()

For aiogram team:
To close the issue we need to add information about this behaviour

@Dizyreal
Copy link
Author

So there is no way to fire .shutdown event when program stops working on Windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Something is missing in docs
Projects
None yet
Development

No branches or pull requests

2 participants