From f658feb65c53be51fb28ff0107105d2fd2ff3332 2008-08-06 03:12:15 From: Gael Varoquaux Date: 2008-08-06 03:12:15 Subject: [PATCH] Better traceback support. --- diff --git a/IPython/frontend/piped_process.py b/IPython/frontend/piped_process.py index 297ef18..94b8ed4 100644 --- a/IPython/frontend/piped_process.py +++ b/IPython/frontend/piped_process.py @@ -17,7 +17,7 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- from subprocess import Popen, PIPE from threading import Thread - +from time import sleep class PipedProcess(Thread): @@ -38,9 +38,16 @@ class PipedProcess(Thread): self.process = process while True: out_char = process.stdout.read(1) - if out_char == '' and process.poll() is not None: - break - self.out_callback(out_char) + if out_char == '': + if process.poll() is not None: + # The process has finished + break + else: + # The process is not giving any interesting + # output. No use polling it immediatly. + sleep(0.1) + else: + self.out_callback(out_char) if self.end_callback is not None: self.end_callback() diff --git a/IPython/frontend/prefilterfrontend.py b/IPython/frontend/prefilterfrontend.py index 9ef2089..d22bb40 100644 --- a/IPython/frontend/prefilterfrontend.py +++ b/IPython/frontend/prefilterfrontend.py @@ -25,7 +25,6 @@ from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap -from IPython.ultraTB import ColorTB from IPython.genutils import Term import pydoc @@ -68,7 +67,7 @@ class PrefilterFrontEnd(LineFrontEndBase): err_callback=self.write, ) self.shell.traceback_trap = SyncTracebackTrap( - formatters=[ColorTB(color_scheme='LightBG'), ] + formatters=self.shell.traceback_trap.formatters ) # Capture and release the outputs, to make sure all the # shadow variables are set diff --git a/IPython/kernel/core/sync_traceback_trap.py b/IPython/kernel/core/sync_traceback_trap.py new file mode 100644 index 0000000..4c0c5b7 --- /dev/null +++ b/IPython/kernel/core/sync_traceback_trap.py @@ -0,0 +1,41 @@ +# encoding: utf-8 + +"""Object to manage sys.excepthook(). + +Synchronous version: prints errors when called. +""" + +__docformat__ = "restructuredtext en" + +#------------------------------------------------------------------------------- +# Copyright (C) 2008 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# Imports +#------------------------------------------------------------------------------- +from traceback_trap import TracebackTrap +from IPython.ultraTB import ColorTB + +class SyncTracebackTrap(TracebackTrap): + + def __init__(self, sync_formatter=None, formatters=None): + TracebackTrap.__init__(self, formatters=formatters) + if sync_formatter is None: + sync_formatter = ColorTB(color_scheme='LightBG') + self.sync_formatter = sync_formatter + + + def hook(self, *args): + """ This method actually implements the hook. + """ + self.args = args + + print self.sync_formatters(*self.args) + + + +