From 0cd619660c83a238bd0192ac5707e1ab591d7408 Mon Sep 17 00:00:00 2001 From: "louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13" Date: Mon, 19 Jul 2010 23:55:20 +0000 Subject: fixed #1587 --- src/common.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/common.py') diff --git a/src/common.py b/src/common.py index 4406e4cb..456f73e5 100644 --- a/src/common.py +++ b/src/common.py @@ -43,9 +43,39 @@ import curses import sys import select import errno -import xmpp import time +class MyStdErr(object): + def __init__(self, fd): + """ + Change sys.stderr to something like /dev/null + to disable any printout on the screen that would + mess everything + """ + self.old_stderr = sys.stderr + sys.stderr = fd + def restaure(self): + """ + Restaure the good ol' sys.stderr, because we need + it in order to print the tracebacks + """ + sys.stderr = self.old_stderr + +my_stderr = MyStdErr(open('/dev/null', 'a')) + +def exception_handler(type_, value, trace): + """ + on any traceback: exit ncurses and print the traceback + then exit the program + """ + my_stderr.restaure() + curses.endwin() + curses.echo() + traceback.print_exception(type_, value, trace, None, sys.stderr) + sys.exit(2) + +import xmpp + def debug(string): """ Print a string in a file. -- cgit v1.2.3