[Python-ideas] Async API

Guido van Rossum guido at python.org
Thu Oct 25 16:43:20 CEST 2012


On Thu, Oct 25, 2012 at 4:46 AM, Laurens Van Houtven <_ at lvh.cc> wrote:
> Sorry, working really long hours these days; just wanted to chime in that
> yes, you can call transport.write with large strings, and the reactor will
> do the right thing under the hood: loseConnection is the polite way of
> dropping a connection, which should wait for all pending writes to finish
> etc.

This seems a decent enough pattern. It also makes it possible to use
one of these things as a substitute for a writable file object, so you
can e.g. use it as sys.stdout or the stream for a
logging.StreamHandler.

Still, I wonder what happens if the socket/pipe/whatever that is
written to is very slow and the program produces too much data. Does
memory just balloon up, or is there some kind of throttling of the
writer? Or a buffer overflow exception? For a totally general solution
I would at least like to have the *option* of doing synchronous
writes.

(I'm asking these questions because I'd like to copy this useful
pattern -- but I want to get the end cases right.)

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list