From 78a7542b4d4af695f7abca6a99eb13264cb0e34a Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Sat, 12 Mar 2016 23:09:57 +0100 Subject: [PATCH] Proper exit on keyboard interrupt --- src/Debug/DebugHook.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Debug/DebugHook.py b/src/Debug/DebugHook.py index 1bb8e1e4..cfd97252 100644 --- a/src/Debug/DebugHook.py +++ b/src/Debug/DebugHook.py @@ -8,6 +8,13 @@ from Config import config last_error = None +def shutdown(): + try: + gevent.spawn(sys.modules["main"].file_server.stop) + gevent.spawn(sys.modules["main"].ui_server.stop) + except Exception, err: + print "Proper shutdown error: %s" % err + sys.exit(0) # Store last error, ignore notify, allow manual error logging def handleError(*args): @@ -19,6 +26,8 @@ def handleError(*args): silent = False if args[0].__name__ != "Notify": last_error = args + if args[0].__name__ == "KeyboardInterrupt": + shutdown() if not silent and args[0].__name__ != "Notify": logging.exception("Unhandled exception") sys.__excepthook__(*args) @@ -26,6 +35,8 @@ def handleError(*args): # Ignore notify errors def handleErrorNotify(*args): + if args[0].__name__ == "KeyboardInterrupt": + shutdown() if args[0].__name__ != "Notify": logging.exception("Unhandled exception") sys.__excepthook__(*args)