Stalled producers

Itay Zandbank zmbq@a...
Wed, 4 Oct 2000 17:38:15 +0300


---------------------- multipart/alternative attachment
I was going through the proxy server example (work_in_progress/http_proxy=
.py) while writing something somewhat similar, and I encountered quite a fe=
w problems with it.

First, the http_proxy_producer is not added as a producer to the http_cha=
nnel. This was quite confusing at first, because I assumed from its name th=
at it's a producer, and was surprised to see its more() method never gets c=
alled. Once I added the producer to the channel (using push_with_producer, =
of course), the channel closed immediately, giving me no chance to collect =
the data, and without calling my stalled() method.

I traced the problem down to async_chat.refill_buffer(). Refill_buffer() =
simply eliminates producers that return an empty response, without ever bot=
hering to check if they are stalled. The writable_for_proxy method doesn't =
fix this, because push_with_producer calls initiate_send, which in turn cal=
ls refill_buffer. So pushing a stalled producer with no input is always goi=
ng to be the last thing you do with that producer (well, more() will be cal=
led once, if that's any consolation).

To fix it, I had to override refill_buffer in my channel, and check wheth=
er the first producer is stalled. If it isn't, I pass control to the origin=
al refill_buffer, something like this:

def refill_buffer(self):
try:
p =3D self.producer_fifo.first()
if p.stalled():
return
except:
pass
http_server.http_channel.refill_buffer(self)



Itay.


---------------------- multipart/alternative attachment
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail-21/medusa-dev/attachments/87b42962/attachment.html

---------------------- multipart/alternative attachment--