runUntil (
eventSource,
suppressErrors=False,
idle=sleep,
)
tick() repeatedly until eventSource fires, returning event
If suppressErrors is true, this method will trap and log all errors
without allowing them to reach the caller. Note that event loop
implementations based on Twisted require that suppressErrors be
used, and should raise a NotImplementedError if it is set to False.
Note that if the event loop's scheduler becomes empty (i.e., there are
no active tasks/callbacks remaining), and eventSource has not fired,
this method may raise StopIteration to indicate this. If you would
prefer that runUntil() simply exit when that happens, just use the
event loop's isEmpty condition as part of an events.AnyOf()
condition passed into runUntil() . Or, if you'd prefer that the event
loop continue indefinitely despite the lack of any active tasks (e.g.
in GUI programs), you may schedule something to be executed in the far
future, or use a task that looks something like: oneDay = eventLoop.sleep(86400)
while True:
yield oneDay; events.resume()
Such a task will only execute once per day, but is sufficient to
ensure that runUntil() does not exit due to an empty schedule. Note
that if you are using a Twisted reactor, you don't need to do this
as an event loop based on a Twisted reactor will only raise
StopIteration if reactor.stop() is called directly (i.e. not via
triggering of eventSource ).
If idle is supplied, it is called with a single argument
representing a float number of seconds that the event loop intends
to be idle for, each time the event loop is idle. The default
for idle is time.sleep , so that the process sleeps between
events.
Note that the idle function will probably never be called when there
are tasks waiting for I/O, when there are tasks that reschedule
themselves at short intervals, or when using Twisted.
|