Save and restore standard streams
This is preferred over using sys.__stdout__ and sys.__stderr__ to return sys.stdout and sys.stderr to their original values.
This commit is contained in:
parent
1f5dd216bf
commit
8dab5bc71d
@ -104,6 +104,8 @@ class PythonEvaluation(Gramplet):
|
|||||||
text = str(self.ebuf.get_text(self.ebuf.get_start_iter(),
|
text = str(self.ebuf.get_text(self.ebuf.get_start_iter(),
|
||||||
self.ebuf.get_end_iter(), False))
|
self.ebuf.get_end_iter(), False))
|
||||||
|
|
||||||
|
oldout = sys.stdout
|
||||||
|
olderr = sys.stderr
|
||||||
outtext = StringIO()
|
outtext = StringIO()
|
||||||
errtext = StringIO()
|
errtext = StringIO()
|
||||||
sys.stdout = outtext
|
sys.stdout = outtext
|
||||||
@ -114,8 +116,8 @@ class PythonEvaluation(Gramplet):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.dbuf.set_text(outtext.getvalue())
|
self.dbuf.set_text(outtext.getvalue())
|
||||||
self.error.set_text(errtext.getvalue())
|
self.error.set_text(errtext.getvalue())
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = oldout
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = olderr
|
||||||
|
|
||||||
def clear_clicked(self, obj):
|
def clear_clicked(self, obj):
|
||||||
self.dbuf.set_text("")
|
self.dbuf.set_text("")
|
||||||
|
Loading…
Reference in New Issue
Block a user