##// END OF EJS Templates
Better traceback support.
Gael Varoquaux -
Show More
@@ -0,0 +1,41 b''
1 # encoding: utf-8
2
3 """Object to manage sys.excepthook().
4
5 Synchronous version: prints errors when called.
6 """
7
8 __docformat__ = "restructuredtext en"
9
10 #-------------------------------------------------------------------------------
11 # Copyright (C) 2008 The IPython Development Team
12 #
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
15 #-------------------------------------------------------------------------------
16
17 #-------------------------------------------------------------------------------
18 # Imports
19 #-------------------------------------------------------------------------------
20 from traceback_trap import TracebackTrap
21 from IPython.ultraTB import ColorTB
22
23 class SyncTracebackTrap(TracebackTrap):
24
25 def __init__(self, sync_formatter=None, formatters=None):
26 TracebackTrap.__init__(self, formatters=formatters)
27 if sync_formatter is None:
28 sync_formatter = ColorTB(color_scheme='LightBG')
29 self.sync_formatter = sync_formatter
30
31
32 def hook(self, *args):
33 """ This method actually implements the hook.
34 """
35 self.args = args
36
37 print self.sync_formatters(*self.args)
38
39
40
41
@@ -17,7 +17,7 b' __docformat__ = "restructuredtext en"'
17 #-------------------------------------------------------------------------------
17 #-------------------------------------------------------------------------------
18 from subprocess import Popen, PIPE
18 from subprocess import Popen, PIPE
19 from threading import Thread
19 from threading import Thread
20
20 from time import sleep
21
21
22 class PipedProcess(Thread):
22 class PipedProcess(Thread):
23
23
@@ -38,9 +38,16 b' class PipedProcess(Thread):'
38 self.process = process
38 self.process = process
39 while True:
39 while True:
40 out_char = process.stdout.read(1)
40 out_char = process.stdout.read(1)
41 if out_char == '' and process.poll() is not None:
41 if out_char == '':
42 break
42 if process.poll() is not None:
43 self.out_callback(out_char)
43 # The process has finished
44 break
45 else:
46 # The process is not giving any interesting
47 # output. No use polling it immediatly.
48 sleep(0.1)
49 else:
50 self.out_callback(out_char)
44
51
45 if self.end_callback is not None:
52 if self.end_callback is not None:
46 self.end_callback()
53 self.end_callback()
@@ -25,7 +25,6 b' from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap'
25
25
26 from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap
26 from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap
27
27
28 from IPython.ultraTB import ColorTB
29 from IPython.genutils import Term
28 from IPython.genutils import Term
30 import pydoc
29 import pydoc
31
30
@@ -68,7 +67,7 b' class PrefilterFrontEnd(LineFrontEndBase):'
68 err_callback=self.write,
67 err_callback=self.write,
69 )
68 )
70 self.shell.traceback_trap = SyncTracebackTrap(
69 self.shell.traceback_trap = SyncTracebackTrap(
71 formatters=[ColorTB(color_scheme='LightBG'), ]
70 formatters=self.shell.traceback_trap.formatters
72 )
71 )
73 # Capture and release the outputs, to make sure all the
72 # Capture and release the outputs, to make sure all the
74 # shadow variables are set
73 # shadow variables are set
General Comments 0
You need to be logged in to leave comments. Login now