Interrupt a task with an error if specified event occurs
yield events.Interrupt( stream.readline(), scheduler.timeout(5) )
line = events.resume()
print "readline() took more than 5 seconds"
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.
Wrap execution of
iterator so that it will raise
eventSource fires before
iterator exits (or aborts), assuming that
Interrupt is yielded to a task.