##// END OF EJS Templates
Changing how IPython.utils.io.Term is handled....
Changing how IPython.utils.io.Term is handled. We used to create a module level IOTerm instance called IPython.utils.io.Term when IPython.utils.io was imported. We now delay this until InteractiveShell.init_io is called. This gives us a chance to override sys.stdout/sys.stderr first. All code that uses IPython.utils.io.Term must refer to by its full name: "IPython.utils.io.Term" and not hold references to it.

File last commit:

r2775:c291d5fa
r2775:c291d5fa
Show More
zmqshell.py
31 lines | 1.1 KiB | text/x-python | PythonLexer
import sys
from subprocess import Popen, PIPE
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
class ZMQInteractiveShell(InteractiveShell):
"""A subclass of InteractiveShell for ZMQ."""
def system(self, cmd):
cmd = self.var_expand(cmd, depth=2)
sys.stdout.flush()
sys.stderr.flush()
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
for line in p.stdout.read().split('\n'):
if len(line) > 0:
print line
for line in p.stderr.read().split('\n'):
if len(line) > 0:
print line
return p.wait()
def init_io(self):
# This will just use sys.stdout and sys.stderr. If you want to
# override sys.stdout and sys.stderr themselves, you need to do that
# *before* instantiating this class, because Term holds onto
# references to the underlying streams.
import IPython.utils.io
Term = IPython.utils.io.IOTerm()
IPython.utils.io.Term = Term
InteractiveShellABC.register(ZMQInteractiveShell)