def echoer(): yield tasklet.WaitForMessages(accept='echo-request') msg = tasklet.get_event() assert isinstance(msg, tasklet.Message) assert msg.sender is not None yield tasklet.Message('echo-reply', dest=msg.sender, value=msg.value)
def process_stdout_sink(chan, buffer, view): timeout = tasklet.WaitForTimeout(200) iowait = tasklet.WaitForIO(chan, priority=1000) msgwait = tasklet.WaitForMessages(accept='quit') while True: yield iowait, msgwait ev = tasklet.get_event() if isinstance(ev, tasklet.Message) and ev.name == 'quit': return assert ev is iowait text = chan.read() buffer.insert(buffer.get_end_iter(), text) view.scroll_to_mark(buffer.get_insert(), 0) ## Now wait for some time, don't let process output "drown" ## the TextView updates yield timeout, tasklet.WaitForMessages(defer='quit') ev = tasklet.get_event() assert ev is timeout
def run(self): timeout = tasklet.WaitForTimeout(1000) msgwait = tasklet.WaitForMessages(accept='quit') for i in range(10, 0, -1): self.dialog.format_secondary_markup( "Time left: <b>%i</b> seconds" % i) yield timeout, msgwait ev = tasklet.get_event() if isinstance(ev, tasklet.Message) and ev.name == 'quit': return elif ev is timeout: pass else: raise AssertionError
def pinger(remote, value): yield tasklet.Message('echo-request', dest=remote, value=value) yield tasklet.WaitForMessages(accept='echo-reply') msg = tasklet.get_event() raise StopIteration(msg.value)