##// END OF EJS Templates
Make the OS-level stdout/stderr capture work in the frontends.
Gael Varoquaux -
Show More
@@ -21,8 +21,7 b' from linefrontendbase import LineFrontEndBase, common_prefix'
21 21
22 22 from IPython.ipmaker import make_IPython
23 23 from IPython.ipapi import IPApi
24 from IPython.kernel.core.file_like import FileLike
25 from IPython.kernel.core.output_trap import OutputTrap
24 from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap
26 25
27 26 from IPython.genutils import Term
28 27 import pydoc
@@ -60,17 +59,9 b' class PrefilterFrontEnd(LineFrontEndBase):'
60 59 # Make sure the raw system call doesn't get called, as we don't
61 60 # have a stdin accessible.
62 61 self._ip.system = xterm_system
63 # Redefine a serie of magics to avoid os.system:
64 # FIXME: I am redefining way too much magics.
65 for alias_name, (_, alias_value) in \
66 _ip.IP.shell.alias_table.iteritems():
67 magic = lambda s : _ip.magic('sx %s %s' % (alias_value, s))
68 setattr(_ip.IP, 'magic_%s' % alias_name, magic)
69 # FIXME: I should create a real file-like object dedicated to this
70 # terminal
71 self.shell.output_trap = OutputTrap(
72 out=FileLike(write_callback=self.write),
73 err=FileLike(write_callback=self.write),
62 self.shell.output_trap = RedirectorOutputTrap(
63 out_callback=self.write,
64 err_callback=self.write,
74 65 )
75 66 # Capture and release the outputs, to make sure all the
76 67 # shadow variables are set
@@ -59,7 +59,10 b' class RedirectorOutputTrap(OutputTrap):'
59 59 redirectors.
60 60 """
61 61 OutputTrap.unset(self)
62 # Flush the redirectors before stopping them
63 self.on_out_write('')
62 64 self.err_redirector.stop()
65 self.on_err_write('')
63 66 self.out_redirector.stop()
64 67
65 68
@@ -69,11 +72,22 b' class RedirectorOutputTrap(OutputTrap):'
69 72 def on_out_write(self, string):
70 73 """ Callback called when there is some Python output on stdout.
71 74 """
72 self.out_callback(self.out_redirector.getvalue() + string)
75 try:
76 self.out_callback(self.out_redirector.getvalue() + string)
77 except:
78 # If tracebacks are happening and we can't see them, it is
79 # quasy impossible to debug
80 self.unset()
81 raise
73 82
74 83 def on_err_write(self, string):
75 84 """ Callback called when there is some Python output on stderr.
76 85 """
77 self.err_callback(self.err_redirector.getvalue() + string)
78
86 try:
87 self.err_callback(self.err_redirector.getvalue() + string)
88 except:
89 # If tracebacks are happening and we can't see them, it is
90 # quasy impossible to debug
91 self.unset()
92 raise
79 93
General Comments 0
You need to be logged in to leave comments. Login now