Interrupt a task with an error if specified event occurs
Usage:
try:
yield events.Interrupt( stream.readline(), scheduler.timeout(5) )
line = events.resume()
except events.Interruption:
print "readline() took more than 5 seconds"
An Interrupt object is an events.ITaskSwitch , so you can only use it
within a task, and you cannot set callbacks on it. If the supplied
generator/iterator exits for any reason, the interruption is cancelled.
Also note that because generator objects are not reusable, neither are
Interrupt objects. You must create an Interrupt for each desired
invocation of the applicable generator. However, the called generator
need not create an additional Interrupt for any nested generator calls,
even though multiple interrupts may be active at the same time. This
allows you to do things like e.g. set one timeout for each line of data
being received, and another timeout for receiving an entire email.
Methods
|
|
__init__
nextAction
|
|
__init__
|
__init__ (
self,
iterator,
eventSource,
errorType=Interruption,
)
Interrupt(iterator,eventSource,errorType=Interruption)
Wrap execution of iterator so that it will raise errorType if
eventSource fires before iterator exits (or aborts), assuming that
the Interrupt is yielded to a task.
|
|
nextAction
|
nextAction (
self,
task=None,
state=None,
)
|
|