[Core] Properly end tasks and process flusher's queue on quit

This commit is contained in:
Twentysix
2017-04-28 18:13:02 +02:00
parent b113a94c52
commit bd341f1875
2 changed files with 25 additions and 13 deletions

View File

@@ -85,5 +85,10 @@ if __name__ == '__main__':
log.critical("Fatal exception", exc_info=e)
loop.run_until_complete(red.logout())
finally:
pending = asyncio.Task.all_tasks(loop=red.loop)
gathered = asyncio.gather(*pending, loop=red.loop)
gathered.cancel()
red.loop.run_until_complete(gathered)
gathered.exception()
sys.exit(red._shutdown_mode.value)