17
17
from twisted.python.runtime import seconds
18
18
from twisted.python import reflect
20
from twisted.internet import defer
20
from twisted.internet import base, defer
300
Provide a deterministic, easily-controlled implementation of
301
L{IReactorTime.callLater}. This is commonly useful for writing
302
deterministic unit tests for code which schedules events using this API.
311
Pretend to be time.time(). This is used internally when an operation
312
such as L{IDelayedCall.reset} needs to determine a a time value
313
relative to the current time.
316
@return: The time which should be considered the current time.
321
def callLater(self, when, what, *a, **kw):
323
See L{twisted.internet.interfaces.IReactorTime.callLater}.
326
base.DelayedCall(self.seconds() + when,
331
self.calls.sort(lambda a, b: cmp(a.getTime(), b.getTime()))
332
return self.calls[-1]
335
def advance(self, amount):
337
Move time on this clock forward by the given amount and run whatever
338
pending calls should be run.
340
@type amount: C{float}
341
@param amount: The number of seconds which to advance this clock's
344
self.rightNow += amount
345
while self.calls and self.calls[0].getTime() <= self.seconds():
346
call = self.calls.pop(0)
348
call.func(*call.args, **call.kw)
351
def pump(self, timings):
353
Advance incrementally by the given set of times.
355
@type timings: iterable of C{float}
357
for amount in timings:
301
367
'SchedulerStopped', 'Cooperator', 'coiterate',