On 01/10/10 13:46, exar...@twistedmatrix.com wrote:
> On 09:41 am, p.may...@imperial.ac.uk wrote:
>> Is there an easy way to make a task.Cooperator instance only execute N
>> ticks / sec, summed across all iterators it's driving? So if you add
>> two
>> iterators, they each run at N/2 per sec, 3 at N/3, etc.
>>
>> It seems like this ought to do it:
>
> Very close!  It took me a while to notice the mistake.
>> N =<rate>
>>
>> def myScheduler(x):
>>    # reschedule N times per second
>>    reactor.callLater(1.0/N, x)
>
> The scheduler function must not return None!  This confuses the
> scheduling code in cooperator and causes it to run too many things in
> parallel.  This mistake could be detected easily by cooperator and a

Ah ha! In fact, it looks like the scheduler must return an object with a 
.cancel() method (obviously an IDelayedCall in the usual case).

I'll open a ticket; presumably it would a) be nice to detect invalid 
return values and b) update the docstring of Cooperator.__init__?

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to