[Twisted-Python] callLater

Jean-Paul Calderone exarkun at divmod.com
Thu Jan 17 17:08:20 EST 2008


On Thu, 17 Jan 2008 18:54:54 -0300, Eduardo Matus <ematus at gmail.com> wrote:
>hey.. the code is to.... dirty.. but look this...
>
>reactor.callLater(3,f)
>
>for x in range(100000000000000): # for example... a big time-consumption
>       #do something
>reactor.callLater(3,g)
>
>the 'g' method will not start at the same time of 'f'
>

Quite so.  Also, network events will go unserviced.  Generally
speaking, you should not do "big time-consuming" things in the
reactor thread.

However, if that is not otherwise a problem for your application,
then you can achieve the goal like this:

    for x in range(1 * 10 ** 14):
        # do something
    reactor.callLater(3, f)
    reactor.callLater(3, g)

You could also put both of the callLater calls before the loop.

There's no API which lets you say "call f 3 seconds from when I
say go... go!"  callLater means "3 seconds from now" (ignoring clock
adjustment issues).

Jean-Paul




More information about the Twisted-Python mailing list