Skip to content

Commit

Permalink
Catch KeyboardInterrupt in blender/yacat for graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
azawlocki committed Nov 23, 2020
1 parent 44e56aa commit ce63a49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 16 additions & 3 deletions examples/blender/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,20 @@ async def worker(ctx: WorkContext, tasks):
task = loop.create_task(main(subnet_tag=args.subnet_tag))
try:
loop.run_until_complete(task)
except (Exception, KeyboardInterrupt) as e:
print(e)
except KeyboardInterrupt:
print(
f"{utils.TEXT_COLOR_YELLOW}"
"Shutting down gracefully, please wait a few seconds "
"or press Ctrl+C to exit immediately..."
f"{utils.TEXT_COLOR_DEFAULT}"
)
task.cancel()
loop.run_until_complete(task)
try:
loop.run_until_complete(task)
print(
f"{utils.TEXT_COLOR_YELLOW}"
"Shutdown completed, thank you for waiting!"
f"{utils.TEXT_COLOR_DEFAULT}"
)
except KeyboardInterrupt:
pass
19 changes: 16 additions & 3 deletions examples/yacat/yacat.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,20 @@ async def worker_find_password(ctx: WorkContext, tasks):

try:
loop.run_until_complete(task)
except (Exception, KeyboardInterrupt) as e:
print(e)
except KeyboardInterrupt:
print(
f"{utils.TEXT_COLOR_YELLOW}"
"Shutting down gracefully, please wait a few seconds "
"or press Ctrl+C to exit immediately..."
f"{utils.TEXT_COLOR_DEFAULT}"
)
task.cancel()
loop.run_until_complete(task)
try:
loop.run_until_complete(task)
print(
f"{utils.TEXT_COLOR_YELLOW}"
"Shutdown completed, thank you for waiting!"
f"{utils.TEXT_COLOR_DEFAULT}"
)
except KeyboardInterrupt:
pass

0 comments on commit ce63a49

Please sign in to comment.