def main(): joe = boring("Joe") ann = boring("Ann") for i in range(5): print (yield take(joe)) print (yield take(ann)) print "You are boring; I'm leaving."
def main(): chan = go_chan(lazy_echo, 1) print (yield take(chan)) chan = go_chan(lazy_echo, 2) yield sleep(1) print (yield take(chan)) yield stop("Done")
def test_parked_put(self): ch = Channel() def putting(): yield sleep(0.005) yield put(ch, 42) go(putting) self.assertEqual((yield take(ch)), 42)
def test_immediate_puts_and_takes(self): ch = Channel(1) i = 0 while i < self.limit: i += 1 yield put(ch, 1) yield take(ch)
def player(name, table): while True: ball = yield take(table) ball.hits += 1 print name, ball.hits yield sleep(0.1) yield put(table, ball)
def test_parked_closed(self): ch = Channel() def closing(): yield sleep(0.005) ch.close() go(closing) self.assertEqual((yield take(ch)), CLOSED)
def main(): chan = Channel() close(chan) print (yield take(chan)) # This would blows up the stack if the implementation is in # correct (e.g. lack of dispatch.run in important places (see # Process._continue)) limit = sys.getrecursionlimit() count = 0 while True: count += 1 yield take(chan) if count > limit: print "Did not blow the stack" break
def main(): n = 100000 leftmost = Channel() right = leftmost left = leftmost for i in range(n): right = Channel() go(f, left, right) left = right def start(c): yield put(c, 1) go(start, right) print (yield take(leftmost))
def test_immediate_buffered(self): ch = Channel(1) yield put(ch, 42) self.assertEqual((yield take(ch)), 42)
def taking(): yield sleep(0.005) yield take(ch)
def test_immediate_put(self): ch = Channel() def putting(): yield put(ch, 42) go(putting) self.assertEqual((yield take(ch)), 42)
def main(): chan = Channel() print "will block" yield put(chan, "channel") # Will not get here print (yield take(chan))
def taking(): yield take(ch)
def test_returning_CLOSED(self): def ident(x): yield stop(x) ch = go_channel(ident, CLOSED) self.assertEqual((yield take(ch)), CLOSED, "CLOSED is delivered") self.assertEqual(ch.is_closed(), True, "output channel is closed")
def test_taking_from_closed_channel(self): i = 0 while i < self.limit: i += 1 yield take(self.ch)
def main(): b = boring("boring!") for i in range(5): print "You say: \"%s\"" % (yield take(b)) print "You are boring; I'm leaving."
def test_immediate_closed(self): ch = Channel() ch.close() self.assertEqual((yield take(ch)), CLOSED)
def main(): chan = Channel(2) yield put(chan, "buffered") yield put(chan, "channel") print (yield take(chan)) print (yield take(chan))
def f(left, right): yield put(left, 1 + (yield take(right)))
def main(): c = fan_in(boring("Joe"), boring("Ann")) for i in range(10): print (yield take(c)) print "You are boring; I'm leaving."
def test_returning_value(self): def ident(x): yield stop(x) ch = go_channel(ident, 42) self.assertEqual((yield take(ch)), 42, "returned value is delivered") self.assertEqual(ch.is_closed(), True, "output channel is closed")
def collect(i): while True: yield put(c, (yield take(i)))