diff options
author | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-08-04 23:54:02 +0000 |
---|---|---|
committer | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-08-04 23:54:02 +0000 |
commit | 94153c490b3ec2dc029a90d179b3cde335060294 (patch) | |
tree | dba7ea26831c5d7f30d806dffa65366c8f36642a /src/poezio.py | |
parent | 567491ba439b5ae1b1f82f3796287d80e2ef653d (diff) | |
download | poezio-94153c490b3ec2dc029a90d179b3cde335060294.tar.gz poezio-94153c490b3ec2dc029a90d179b3cde335060294.tar.bz2 poezio-94153c490b3ec2dc029a90d179b3cde335060294.tar.xz poezio-94153c490b3ec2dc029a90d179b3cde335060294.zip |
fixes the sys.excepthook thread bug, and fix the traceback on joining a room with non-ascii chars
Diffstat (limited to 'src/poezio.py')
-rw-r--r-- | src/poezio.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/poezio.py b/src/poezio.py index a73924d8..83eba23c 100644 --- a/src/poezio.py +++ b/src/poezio.py @@ -21,9 +21,28 @@ Starting point of poezio. Launches both the Connection and Gui """ +import threading import sys -import traceback -import curses + +def installThreadExcepthook(): + """ + Workaround for sys.excepthook thread bug + See http://bugs.python.org/issue1230540 + Python, you made me sad :( + """ + init_old = threading.Thread.__init__ + def init(self, *args, **kwargs): + init_old(self, *args, **kwargs) + run_old = self.run + def run_with_except_hook(*args, **kw): + try: + run_old(*args, **kw) + except (KeyboardInterrupt, SystemExit): + raise + except: + sys.excepthook(*sys.exc_info()) + self.run = run_with_except_hook + threading.Thread.__init__ = init class MyStdErr(object): def __init__(self, fd): @@ -52,11 +71,14 @@ def exception_handler(type_, value, trace): curses.endwin() curses.echo() traceback.print_exception(type_, value, trace, None, sys.stderr) - sys.exit(2) + import os # used to quit the program even from a thread + os.abort() sys.excepthook = exception_handler -import common +import sys +import curses +import signal from connection import Connection from multiuserchat import MultiUserChat @@ -64,7 +86,6 @@ from config import config from gui import Gui from curses import initscr -import signal signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c def main(): @@ -80,4 +101,5 @@ def main(): gui.main_loop(stdscr) if __name__ == '__main__': + installThreadExcepthook() main() |