[IPython-dev] Fwd: IPython and closing sys.stdout
Ville M. Vainio
vivainio at gmail.com
Tue Oct 3 12:34:55 EDT 2006
On 9/27/06, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
> In my opinion, the best thing to do would be to subclass InteractiveConsole
> and provide a more robust raw_input() method. Ideally, I think you'd want
> to dup() the file descriptors for sys.{stdin,stdout} and use those instead
> of calling the builtin raw_input(). Something like (untested):
>
> class IC(code.InteractiveConsole):
> def __init__(self):
> code.InteractiveConsole.__init__(self)
> self.input = os.fdopen(os.dup(sys.stdin.fileno()))
> self.output = os.fdopen(os.dup(sys.stdout.fileno()))
> self.error = os.fdopen(os.dup(sys.stderr.fileno()))
>
> def raw_input(self, prompt=""):
> if prompt:
> self.output.write(prompt):
> self.output.flush()
> return self.input.readline()
>
> def write(self, data):
> self.error.write(data)
>
> Also, the runcode() method will have to be overridden to use self.output
> instead of sys.stdout. Those couple changes should (hopefully) insulate
> IPython from such user wackiness.
It seems code.InteractiveConsole was removed from ipython
purposefully, so this would seem to be going to the wrong direction
(Fernando?). I put the ValueError cathing (which was originally for
quit() on py2.5) back in, but there are lots of plain print statements
around ipython and intact sys.std[in | out] would seem necessary, for
a while at least.
At least now we fail with a helpful message, instead of infinite loop.
--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
More information about the IPython-dev
mailing list