Skip to content

Commit

Permalink
#626: when we get a signal we will exit on, remove the exception hook…
Browse files Browse the repository at this point in the history
… hacks

git-svn-id: https://xpra.org/svn/Xpra/trunk@9197 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 29, 2015
1 parent 912729f commit 3fc8ddc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/xpra/gtk_common/quit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ def gtk_main_quit_forever():
# propagate it from Python code. Sigh.) But sys.excepthook will still get
# called with such exceptions.
_hooked = False
_oldhook = None
def gtk_main_quit_on_fatal_exceptions_enable():
global _hooked
global _hooked, _oldhook
if _hooked:
return
_hooked = True
oldhook = sys.excepthook
_oldhook = sys.excepthook
def gtk_main_quit_on_fatal_exception(etype, val, tb):
if issubclass(etype, (KeyboardInterrupt, SystemExit)):
print("Shutting down main-loop")
Expand All @@ -67,5 +68,12 @@ def gtk_main_quit_on_fatal_exception(etype, val, tb):
print(traceback.print_exception(etype, val, tb))
print("Maximum recursion depth exceeded")
else:
return oldhook(etype, val, tb)
return _oldhook(etype, val, tb)
sys.excepthook = gtk_main_quit_on_fatal_exception

def gtk_main_quit_on_fatal_exceptions_disable():
global __oldhook
oh = _oldhook
if oh:
_oldhook = None
sys.excepthook = oh
8 changes: 7 additions & 1 deletion src/xpra/server/gtk_server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
screenlog = Logger("server", "screen")

from xpra.gtk_common.quit import (gtk_main_quit_really,
gtk_main_quit_on_fatal_exceptions_enable)
gtk_main_quit_on_fatal_exceptions_enable,
gtk_main_quit_on_fatal_exceptions_disable)
from xpra.server.server_base import ServerBase
from xpra.gtk_common.gtk_util import get_gtk_version_info, gtk_main
from xpra.util import updict
Expand All @@ -40,8 +41,13 @@ def watch_keymap_changes(self):
### Set up keymap change notification:
gtk.gdk.keymap_get_default().connect("keys-changed", self._keys_changed)

def signal_quit(self, signum, frame):
gtk_main_quit_on_fatal_exceptions_disable()
ServerBase.signal_quit(self, signum, frame)

def do_quit(self):
log("do_quit: calling gtk_main_quit_really")
gtk_main_quit_on_fatal_exceptions_disable()
gtk_main_quit_really()
log("do_quit: gtk_main_quit_really done")

Expand Down

0 comments on commit 3fc8ddc

Please sign in to comment.