[Twisted-Python] callLater(0) is A BIG LIE
Phillip J. Eby
pje at telecommunity.com
Mon Nov 1 12:44:12 EST 2004
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.)
More information about the Twisted-Python
mailing list