[Twisted-Python] twisted.internet.interfaces.IReactorTime.callAt

Bob Ippolito bob at redivi.com
Tue Apr 1 20:51:22 MST 2003


I think it's useful to have a callAt function in the reactor.  Itamar 
mentioned that one of the design goals of the reactor is to have a 
minimal interface.  However, IMHO it should be added to IReactor due to 
the utility (log rotation, scheduled events, etc.) of such a 
convenience function and the fact it takes a newbie a lot longer to 
find something hidden away in a utils package (for example, today, 
neither Itamar nor I knew that there was a function in t.i.utils to 
start a process and return a Deferred with the stdout of that 
process!).  The implementation is very simple, it looks like this:

     def callAt(self, when, f, *args, **kw):
         """See twisted.internet.interfaces.IReactorTime.callAt.
         """
         return self.callLater(max(0.0, when - time()), f, *args, **kw)

     def callAt(self, when, callable, *args, **kw):
         """Call a function at a specified float time

         @type when:  C{float}
         @param when: The approximate unix time (seconds since the 
Epoch) to
                      call the callable.  It will be called on or after 
the specified time;
                      immediately if the current or a past time is given.

         @param callable: the callable object to call later.

         @param args: the arguments to call it with.

         @param kw: they keyword arguments to call it with.

         @returns: An L{IDelayedCall} object that can be used to cancel
                   the scheduled call, by calling its C{cancel()} method.
                   It also may be rescheduled by calling its C{delay()}
                   or C{reset()} methods.
         """

-bob





More information about the Twisted-Python mailing list