[test] Shutdown handler

pull/143/head
ZetGo | Aleksej K. 2025-06-06 01:28:55 +03:00
parent 5f8f69dd5f
commit 0731aa4c35
1 changed files with 16 additions and 32 deletions

View File

@ -972,9 +972,7 @@ class Heroku:
await asyncio.gather(*[self.amain_wrapper(client) for client in self.clients]) await asyncio.gather(*[self.amain_wrapper(client) for client in self.clients])
async def _shutdown_handler(self, final: bool = False): async def _shutdown_handler(self):
if not final:
logging.info("Ctrl + C....... Bye?")
for client in self.clients: for client in self.clients:
inline = getattr(client.loader, "inline", None) inline = getattr(client.loader, "inline", None)
if inline: if inline:
@ -985,24 +983,10 @@ class Heroku:
await inline.bot.session.close() await inline.bot.session.close()
for c in self.clients: for c in self.clients:
await c.disconnect() await c.disconnect()
logging.info("Bye!")
else:
for client in self.clients:
inline = getattr(client.loader, "inline", None)
if inline:
inline._task.cancel()
inline._cleaner_task.cancel()
try:
await inline._dp.stop_polling()
except: pass
try:
await inline.bot.session.close()
except: pass
for c in self.clients:
await c.disconnect()
for task in asyncio.all_tasks(): for task in asyncio.all_tasks():
if task is not asyncio.current_task(): if task is not asyncio.current_task():
task.cancel() task.cancel()
self.loop.stop()
def main(self): def main(self):
"""Main entrypoint""" """Main entrypoint"""
@ -1013,7 +997,7 @@ class Heroku:
try: try:
self.loop.run_until_complete(self._main()) self.loop.run_until_complete(self._main())
finally: finally:
self.loop.run_until_complete(self._shutdown_handler(True)) self.loop.run_until_complete(self._shutdown_handler())
herokutl.extensions.html.CUSTOM_EMOJIS = not get_config_key("disable_custom_emojis") herokutl.extensions.html.CUSTOM_EMOJIS = not get_config_key("disable_custom_emojis")