[IPython-dev] Re: Changes to Notebook Format

Hans Meine hans_meine at gmx.net
Tue Aug 2 05:58:45 EDT 2005


On Monday 01 August 2005 21:51, Fernando Perez wrote:
> Fernando Perez wrote:
> > Oh, I don't disagree with you that it would be _nice_ to have that
> > interleaving.  The problem is _how_ to do it.  On the implementation end
> > of things (where desires have to become reality), you have an object
> > which can track each of the output streams (stdout/err), and that's about
> > it.  Those animals are buffered to begin with, so knowing in a reliable
> > way when data came into each is not really possible, I think even for a
> > plain shell.
>
> mmh, scratch that.  Upon thinking a bit more, it seems to me that since our
> output proxies have to trap all write() calls, they should be able to
> timestamp each one of them internally.  These timestamps should correspond
> with the actuall call time, not with the results of output showing up on
> the buffered output, so they are indeed enough to reconstruct the call
> sequence.

That's exactly the way we did it in our python shell for colored ouput (stderr 
in red).

> The implementation would be still a bit delicate, as you want to tag output
> to each stream as a separate kind, but multiple consecutive write() calls
> to one kind of stream should not create new cells.  Instead, they should
> continue writing to the currently open one, unless the other stream has had
> a write() call made, time at which the code should open a new cell to
> switch streams. It seems possible, but a fair bit of work.

Indeed, since we had no "cells" (no notebook), we did not have that problem, 
but that does not seem too hard, no?
e.g. sth. along the lines of

class ErrorStream:
   def write(s):
      lastCell = {retrieve somehow}
      if lastCell.type() == ErrorOutput:
  lastCell.append(s)
      else:
         appendCell(ErrorOutputCell(s))

Greets,
  Hans




More information about the IPython-dev mailing list