Skip to content

Commit

Permalink
fix: exit gracefully on ctrl+c
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Jan 26, 2024
1 parent dc6a4b4 commit 1f77378
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ async def main(stop_event=asyncio.Event()):
asyncio.create_task(ws_handler.serve(host, port)),
asyncio.create_task(pinecil_monitor.monitor(stop_event)),
]
await asyncio.gather(*tasks)
try:
await asyncio.gather(*tasks)
except KeyboardInterrupt:
stop_event.set()
for task in tasks:
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
logging.info("Gracefully shutting down")


if __name__ == "__main__":
asyncio.run(main())
try:
asyncio.run(main())
except KeyboardInterrupt:
pass

0 comments on commit 1f77378

Please sign in to comment.