On Fri, Sep 28, 2012 at 3:00 PM, A Jesse Jiryu Davis
<
ajd...@cs.oberlin.edu> wrote:
> Ah, I hadn't been following your BaseIOStream development. This looks
> *closer* to what I'm thinking about, but it's still limited to reading and
> writing bytes from something with a file-descriptor. I'm hoping for a more
> general interface for streaming *things*.
If you want streaming of general objects then I think BaseIOStream may
actually be moving in the wrong direction. The methods defined on
IOStream and PipeIOStream could be mapped to something like Node's
streams, but at the BaseIOStream level everything is distinctly
bytes-oriented. If we had an interface like what you're proposing
then instead of BaseIOStream as a superclass, we might have a
BufferedStream class that wraps a SocketStream or PipeStream.
>
> A small answer to your question, "What sort of capabilities are you thinking
> of borrowing from Node's streams?": Perhaps the readable and writable
> attributes and the pause() and resume() methods would be nice for Tornado
> streams.
I can see the need for pause/resume in an asynchronous object queue,
but I don't think it makes sense in conjunction with the other
IOStream methods. An IOStream is paused if there are no pending read
operations, but if there is an outstanding read why would you want to
pause? I suppose the one case where it would be useful would be if
you're forgoing IOStream's buffering and just using read_until_close
with a streaming_callback, although in that case maybe it's better to
introduce a read_some() method that would let this be structured as a
series of independent reads instead of one large one.
>
> A big answer: What I'm attracted to in Node is how its streams are a
> standard API for shipping data around, whether that data is bytes or objects
> or something else. For example the latest Node driver for MongoDB has a
> CursorStream that reads documents.
>
> This standard makes streams composable and pluggable. There's no similar
> agreement among Tornado-related libraries. For example, OutputTransform is a
> different API from IOStream. The Tornado database drivers don't provide an
> IOStream-like interface for getting rows from cursors.
>
> I could get the show started by making Motor's GridFS interface more
> IOStream-like, but returning Python dictionaries instead of bytes.
I think it probably makes sense to keep the byte and object interfaces
distinct. With objects you usually want to work with one object at a
time, while with bytes you nearly always want multiple bytes (and
there are well-established patterns for specifying this). I'd look at
Queue (or Node's streams) rather than IOStream as a role model for
this interface.
-Ben