コード例 #1
0
ファイル: pingpong.py プロジェクト: ubolonton/twisted-csp
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)
コード例 #2
0
 def test_parked_taken(self):
     ch = Channel()
     def taking():
         yield sleep(0.005)
         yield take(ch)
     go(taking)
     self.assertEqual((yield put(ch, 42)), True)
コード例 #3
0
 def test_parked_closed(self):
     ch = Channel()
     def closing():
         yield sleep(0.005)
         ch.close()
     go(closing)
     self.assertEqual((yield put(ch, 42)), False)
コード例 #4
0
 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)
コード例 #5
0
ファイル: pingpong.py プロジェクト: ubolonton/twisted-csp
def main():
    table = Channel()

    go(player, "ping", table)
    go(player, "pong", table)

    yield put(table, Ball())
    yield sleep(1)
コード例 #6
0
 def test_default_value(self):
     ch = Channel(1)
     r = yield alts([ch], default=42)
     self.assertEqual(r.value, 42)
     self.assertEqual(r.channel, DEFAULT)
     yield put(ch, 53)
     r = yield alts([ch], default=42)
     self.assertEqual(r.value, 53)
     self.assertEqual(r.channel, ch)
コード例 #7
0
 def test_no_priority(self):
     nums = range(50)
     chs = [Channel(1) for _ in nums]
     for i in nums:
         yield put(chs[i], i)
     values = []
     for _ in nums:
         values.append((yield alts(chs)).value)
     self.assertNotEqual(values, nums)
コード例 #8
0
 def collect(i):
     while True:
         yield put(c, (yield take(i)))
コード例 #9
0
 def putting():
     yield put(ch, 42)
コード例 #10
0
 def test_immediate_closed(self):
     ch = Channel()
     ch.close()
     self.assertEqual((yield put(ch, 42)), False)
コード例 #11
0
ファイル: boring.py プロジェクト: ubolonton/twisted-csp
 def _do():
     i = 0
     while True:
         yield put(c, "%s %d" % (message, i))
         yield sleep(random.random())
         i += 1
コード例 #12
0
ファイル: blocking.py プロジェクト: ubolonton/twisted-csp
def main():
    chan = Channel()
    print "will block"
    yield put(chan, "channel")
    # Will not get here
    print (yield take(chan))
コード例 #13
0
 def test_immediate_buffered(self):
     ch = Channel(1)
     self.assertEqual((yield put(ch, 42)), True)
コード例 #14
0
 def test_putting_onto_closed_channel(self):
     i = 0
     while i < self.limit:
         i += 1
         yield put(self.ch, 42)
コード例 #15
0
 def test_immediate_taken(self):
     ch = Channel()
     def taking():
         yield take(ch)
     go(taking)
     self.assertEqual((yield put(ch, 42)), True)
コード例 #16
0
ファイル: daisy_chain.py プロジェクト: ubolonton/twisted-csp
def f(left, right):
    yield put(left, 1 + (yield take(right)))
コード例 #17
0
 def test_immediate_buffered(self):
     ch = Channel(1)
     yield put(ch, 42)
     self.assertEqual((yield take(ch)), 42)
コード例 #18
0
 def putting():
     yield sleep(0.005)
     yield put(ch, 42)
コード例 #19
0
ファイル: buffered.py プロジェクト: ubolonton/twisted-csp
def main():
    chan = Channel(2)
    yield put(chan, "buffered")
    yield put(chan, "channel")
    print (yield take(chan))
    print (yield take(chan))
コード例 #20
0
 def collect():
     while True:
         value, _ = yield alts([input1, input2])
         yield put(c, value)
コード例 #21
0
ファイル: select.py プロジェクト: ubolonton/twisted-csp
def produce(chan, value):
    yield sleep(0.1)
    yield put(chan, value)
コード例 #22
0
ファイル: daisy_chain.py プロジェクト: ubolonton/twisted-csp
 def start(c):
     yield put(c, 1)