<br><br><div class="gmail_quote">On Thu, Oct 25, 2012 at 10:43 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Thu, Oct 25, 2012 at 4:46 AM, Laurens Van Houtven <_@lvh.cc> wrote:<br>
> Sorry, working really long hours these days; just wanted to chime in that<br>
> yes, you can call transport.write with large strings, and the reactor will<br>
> do the right thing under the hood: loseConnection is the polite way of<br>
> dropping a connection, which should wait for all pending writes to finish<br>
> etc.<br>
<br>
</div></div>This seems a decent enough pattern. It also makes it possible to use<br>
one of these things as a substitute for a writable file object, so you<br>
can e.g. use it as sys.stdout or the stream for a<br>
logging.StreamHandler.<br>
<br>
Still, I wonder what happens if the socket/pipe/whatever that is<br>
written to is very slow and the program produces too much data. Does<br>
memory just balloon up, or is there some kind of throttling of the<br>
writer? Or a buffer overflow exception? For a totally general solution<br>
I would at least like to have the *option* of doing synchronous<br>
writes.<br>
<br>
(I'm asking these questions because I'd like to copy this useful<br>
pattern -- but I want to get the end cases right.)<br clear="all"></blockquote><div><br>There's a callback that gets called saying "your buffer is too full". This is the producer/consumer API people have referred to. It's not the best API in the world, and Glyph is working on an improvement, but that's the basic idea. The general move is towards a push API - push as much data as you can until you're told to stop.<br>
<br>Tornado has a "tell me when this write is removed from the buffer and actually written to the socket" callback. This is more of a pull approach; you write some data, and get notified when you should write some more.<br>
</div></div><br>--Itamar<br>