mirror of https://github.com/coddrago/Heroku
[test] Shutdown handler
parent
5f8f69dd5f
commit
0731aa4c35
|
@ -972,37 +972,21 @@ 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:
|
for client in self.clients:
|
||||||
logging.info("Ctrl + C....... Bye?")
|
inline = getattr(client.loader, "inline", None)
|
||||||
for client in self.clients:
|
if inline:
|
||||||
inline = getattr(client.loader, "inline", None)
|
for t in (inline._task, inline._cleaner_task):
|
||||||
if inline:
|
if t:
|
||||||
for t in (inline._task, inline._cleaner_task):
|
t.cancel()
|
||||||
if t:
|
await inline._dp.stop_polling()
|
||||||
t.cancel()
|
await inline.bot.session.close()
|
||||||
await inline._dp.stop_polling()
|
for c in self.clients:
|
||||||
await inline.bot.session.close()
|
await c.disconnect()
|
||||||
for c in self.clients:
|
for task in asyncio.all_tasks():
|
||||||
await c.disconnect()
|
if task is not asyncio.current_task():
|
||||||
logging.info("Bye!")
|
task.cancel()
|
||||||
else:
|
self.loop.stop()
|
||||||
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():
|
|
||||||
if task is not asyncio.current_task():
|
|
||||||
task.cancel()
|
|
||||||
|
|
||||||
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")
|
||||||
|
|
Loading…
Reference in New Issue