[Twisted-Python] callLater(0) is A BIG LIE
Bob Ippolito
bob at redivi.com
Mon Nov 1 12:51:33 EST 2004
On Nov 1, 2004, at 12:44, Phillip J. Eby wrote:
> At 03:41 AM 11/1/04 -0700, Jonathan Simms wrote:
>> I'd like to offer some reflections on the reactor and facilitate some
>> conversation on a subject that's been causing me much frustration:
>>
>> the twisted idiom, "callLater(0)"
>>
>> While it seems that this is a DelayedCall, it really is a lie. It has
>> nothing to do with time at all, it is a very *convenient* lie that we
>> all have accepted, but is a lie nonetheless.
>>
>> We all know this means "call function f in the next reactor
>> iteration",
>
> No, it means, "call f *at least* 0 seconds from now", just as
> 'callLater(1,f)' means "call f *at least* 1 second from now".
>
> AFAIK, iterations have nothing to do with it. In fact, I believe that
> on a machine that is sufficiently fast relative to the precision of
> its 'time()' function, it was possible for a 'callLater(0,f)' to be
> invoked in the same iteration, in some versions of Twisted.
>
> That being said, I think your example points out code in Twisted
> that's relying on 'callLater(0,f)' meaning "call f in the next
> iteration", and that code should probably be considered broken. Only
> a non-zero value should guarantee that the code will not run in the
> current iteration.
>
> (Disclaimer: I'm not a Twisted developer, but I've developed PEAK's
> scheduler system to interoperate with Twisted and vice versa, so I've
> had occasion to dabble in timer precision and iteration issues.)
Actually callLater(0, ....) was an edge case up until recently (I hope
it got fixed?) where it DID run in the current iteration.. a timer that
fired another timer with 0 delay would cause the timer processing to
never finish, so IO wouldn't happen anymore.
Of course, everyone expected it to mean "call function f in the next
reactor iteration".. but it didn't :)
-bob
More information about the Twisted-Python
mailing list