Comments on: producer.py http://laurentszyster.be/blog/producer/ Python on Peers Fri, 18 May 2012 14:43:43 +0000 http://wordpress.org/?v=1.5.1.3 by: Laurent Szyster http://laurentszyster.be/blog/producer/#comment-443 Thu, 18 May 2006 08:32:24 +0000 http://laurentszyster.be/blog/producer/#comment-443 To Rene: Avoiding an error condition on more () when it would block is achieved by excluding the channel from the list of socket polled for output when the first producer in the channel's output_fifo is stalled. Developers don't need to worry about producer stalling in an async_chat channel, because its writable () and handle_write () methods are carefully designed so that such error conditions do not occur. If the first producer is stalled, writable() will be false and more() won't be called in the event loop. If you do have to call more () somewhere else, independantly from the event loop, it will most probably be in an accumulator like the composite producer when it globs output. Then, but it is a rare case, you will have to check for the producer beeing stalled. Regards, To Rene:

Avoiding an error condition on more () when it would block is achieved by excluding the channel from the list of socket polled for output when the first producer in the channel’s output_fifo is stalled.

Developers don’t need to worry about producer stalling in an async_chat channel, because its writable () and handle_write () methods are carefully designed so that such error conditions do not occur. If the first producer is stalled, writable() will be false and more() won’t be called in the event loop.

If you do have to call more () somewhere else, independantly from the event loop, it will most probably be in an accumulator like the composite producer when it globs output. Then, but it is a rare case, you will have to check for the producer beeing stalled.

Regards,

]]>
by: Rene Dudfield http://laurentszyster.be/blog/producer/#comment-421 Wed, 17 May 2006 23:26:18 +0000 http://laurentszyster.be/blog/producer/#comment-421 Thinking about it more... more() should raise an exception if it is going to block. This is to avoid a race condition. It is the old peek, and use pattern. if producer_stalled(): # in this time between method calls the producer may not be stalled. # meaning you miss a chance to call more() more() In practice it might not be an issue. Here is the other way... try: bla = more() except ProducerStalled: print "moving on!" I'd like to hear why it isn't a race condition. Or if it is, why it doesn't matter. Thinking about it more…

more() should raise an exception if it is going to block. This is to avoid a race condition.

It is the old peek, and use pattern.

if producer_stalled():
# in this time between method calls the producer may not be stalled.
# meaning you miss a chance to call more()
more()

In practice it might not be an issue.

Here is the other way…
try:
bla = more()
except ProducerStalled:
print “moving on!”

I’d like to hear why it isn’t a race condition. Or if it is, why it doesn’t matter.

]]>
by: Laurent Szyster http://laurentszyster.be/blog/producer/#comment-408 Wed, 17 May 2006 13:55:04 +0000 http://laurentszyster.be/blog/producer/#comment-408 To Rene: There are at least two reasons I can think of for not changing that interface into a "positive" one. The first is that one should not fix what ain't broken. I found producer_stalled in the experimental section of Medusa sources and kept it as it was. The second reason is that use case of the interface is indeed a "negative" as found in the Async_chat.writable () method. Anyway, thanks for the comment and suggestion. To Rene:

There are at least two reasons I can think of for not changing that interface into a “positive” one. The first is that one should not fix what ain’t broken. I found producer_stalled in the experimental section of Medusa sources and kept it as it was. The second reason is that use case of the interface is indeed a “negative” as found in the Async_chat.writable () method.

Anyway, thanks for the comment and suggestion.

]]>
by: Rene Dudfield http://laurentszyster.be/blog/producer/#comment-405 Tue, 16 May 2006 01:51:52 +0000 http://laurentszyster.be/blog/producer/#comment-405 I think producer_stalled() has a negative in it. I like to keep negatives out, and left negatives be shown with not. I think this makes it not less clear... I mean more clear ;) eg. not producer_stalled() means that there is not not some more. Maybe some_more() instead? I think producer_stalled() has a negative in it. I like to keep negatives out, and left negatives be shown with not. I think this makes it not less clear… I mean more clear ;)

eg. not producer_stalled() means that there is not not some more.

Maybe some_more() instead?

]]>