asyncore and (missing) timeout

Dave Brueck dave at pythonapocrypha.com
Mon Jun 23 15:13:28 EDT 2003


On Monday 23 June 2003 07:32 am, Pierre HANSER wrote:
> I'm trying to use asyncore with some timeout in the poll loop
> to not use all my cpu.
>
> The problem I have is that operationnal sockets always return
> immediatly to a select with write, as you CAN write immediatly on them.

A _new_ socket will be writable, yes, but after you write data to it that may 
not be the case. Either way, you only call select/poll on it if you are 
_interested_ in writing to it. In asyncore terms, you return true from 
writable if and only if you have data that you want to write.

> I've tried a minor modification:

You won't need to modify asyncore to do what you're trying to do.

> The solution of returning a significant value in "writable" function
> is a bit cumbersome as you have to manage there the fact you will
> want to write something one day...

By definition, the readable and writable methods are _supposed_ to return 
values that make sense as asyncore drives its behavior off those values. The 
high CPU problem you're having goes away if you return values that truly 
reflect the state of your app.

Also, I better include the standard "have you tried Twisted yet?" response - 
many people seem to like it (although there is terrific educational value in 
getting your asyncore-based program working ;-) ).

HTH,
-Dave





More information about the Python-list mailing list