Respond to ctrl-c exits

This commit is contained in:
Luke Murphy 2020-07-23 12:36:28 +02:00
parent 41634265f0
commit a651c3fad9
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -5,6 +5,7 @@ import logging
import os import os
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from signal import SIGINT, SIGTERM
import asyncio_glib import asyncio_glib
import gi import gi
@ -142,13 +143,18 @@ class DropShip:
async def main(): async def main():
"""The application entrypoint.""" """The application entrypoint."""
dropship = DropShip() try:
await dropship._running dropship = DropShip()
await dropship._running
except asyncio.CancelledError:
pass
if __name__ == "__main__": if __name__ == "__main__":
try: try:
# TODO(decentral1se): also handle Ctrl-C escape from terminal main_task = asyncio.ensure_future(main())
loop.run_until_complete(main()) loop.add_signal_handler(SIGINT, main_task.cancel)
loop.add_signal_handler(SIGTERM, main_task.cancel)
loop.run_until_complete(main_task)
finally: finally:
loop.close() loop.close()