enable the tracebacks

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-06-13 18:58:39 +00:00
parent 9c492501f4
commit 08c81a900c
3 changed files with 34 additions and 21 deletions

View file

@ -33,13 +33,13 @@
"""
various useful functions
"""
import base64
import os
import mimetypes
import hashlib
import subprocess
import curses
import traceback
import sys
import select
import errno
@ -54,16 +54,6 @@ def debug(string):
fdes.write(string)
fdes.close()
def exception_handler(type_, value, trace):
"""
on any traceback: exit ncurses and print the traceback
then exit the program
"""
curses.endwin()
curses.echo()
traceback.print_exception(type_, value, trace, None, sys.stderr)
sys.exit(2)
def get_base64_from_file(path):
"""
Convert the content of a file to base64

View file

@ -30,7 +30,6 @@ import xmpp
from config import config
from logging import logger
from handler import Handler
from common import exception_handler
import threading
class Connection(threading.Thread):
@ -57,7 +56,6 @@ class Connection(threading.Thread):
run in a thread
connect to server
"""
sys.excepthook = exception_handler
if not self.connect_to_server(self.server, self.port):
self.handler.emit('error', msg='Could not connect to server')
sys.exit(-1)

View file

@ -21,25 +21,50 @@
Starting point of poezio. Launches both the Connection and Gui
"""
import sys
import traceback
import curses
# disable any printout (this would mess the display)
if len(sys.argv) == 2:
sys.stderr = open('errors', 'a')
else:
sys.stderr = open('/dev/null', 'a')
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
"""
global my_stderr
my_stderr.restaure()
curses.endwin()
curses.echo()
traceback.print_exception(type_, value, trace, None, sys.stderr)
sys.exit(2)
sys.excepthook = exception_handler
from connection import Connection
from multiuserchat import MultiUserChat
from config import config
from gui import Gui
from curses import initscr
from common import exception_handler
import signal
signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
sys.excepthook = exception_handler
def main():
"""
main function