예제 #1
0
 def test_behavior(self):
     # Obviously we cannot test an infinite buffer,
     # but we can just test a huge one's behavior.
     chan = gochans.AsyncChannel()
     for _ in range(10000):
         chan.send()
     chan.close()
     for _ in chan:
         pass
예제 #2
0
 def test_range_with_closed_channel(self):
     chan = self.makechan()
     sendCount = min(chan.maxsize, 5)
     data2send = list(range(sendCount))
     for data in data2send:
         be.run(chan.send, data)
     chan.close()
     items = [o for o in chan]
     self.assertEqual(items, data2send)
예제 #3
0
 def test_range_with_closed_channel(self):
     chan = self.makechan()
     sendCount = min(chan.maxsize, 5)
     data2send = list(range(sendCount))
     for data in data2send:
         be.run(chan.send, data)
     chan.close()
     items = [o for o in chan]
     self.assertEqual(items, data2send)
예제 #4
0
 def test_behavior(self):
     # Obviously we cannot test an infinite buffer,
     # but we can just test a huge one's behavior.
     chan = gochans.AsyncChannel()
     for _ in range(10000):
         chan.send()
     chan.close()
     for _ in chan:
         pass
예제 #5
0
    def test_recv_and_send_with_room_do_not_block(self):
        resultschan = gochans.BufferedChannel(5)
        endchan = gochans.SyncChannel()

        def square(x):
            return x * x

        def func():
            for num in range(5):
                resultschan.send(square(num))
            endchan.send()

        goless.go(func)
        # Waiting on the endchan tells us our results are
        # queued up in resultschan
        endchan.recv()
        got = [resultschan.recv() for _ in range(5)]
        ideal = [square(i) for i in range(5)]
        self.assertEqual(got, ideal)
예제 #6
0
def prime():
    count = 1
    if platform.python_implementation() == 'PyPy':
        count = 10
    global WRITE_ENABLED
    WRITE_ENABLED = False
    for _ in range(count):
        bench_channels()
        bench_selects()
    WRITE_ENABLED = True
예제 #7
0
def prime():
    count = 1
    if platform.python_implementation() == 'PyPy':
        count = 10
    global WRITE_ENABLED
    WRITE_ENABLED = False
    for _ in range(count):
        bench_channels()
        bench_selects()
    WRITE_ENABLED = True
예제 #8
0
    def test_recv_and_send_with_room_do_not_block(self):
        resultschan = gochans.BufferedChannel(5)
        endchan = gochans.SyncChannel()

        def square(x):
            return x * x

        def func():
            for num in range(5):
                resultschan.send(square(num))
            endchan.send()

        goless.go(func)
        # Waiting on the endchan tells us our results are
        # queued up in resultschan
        endchan.recv()
        got = [resultschan.recv() for _ in range(5)]
        ideal = [square(i) for i in range(5)]
        self.assertEqual(got, ideal)
예제 #9
0
def bench_channel(chan_size):
    c = chan(chan_size)

    def func():
        for _ in range(QUEUE_LEN):
            c.send(0)
        c.close()
    count = 0

    go(func)
    start = time.clock()
    for _ in range(QUEUE_LEN):
        c.recv()
        count += 1
    end = time.clock()
    return end - start
예제 #10
0
def bench_channel(chan_size):
    c = chan(chan_size)

    def func():
        for _ in range(QUEUE_LEN):
            c.send(0)
        c.close()

    count = 0

    go(func)
    start = time.clock()
    for _ in range(QUEUE_LEN):
        c.recv()
        count += 1
    end = time.clock()
    return end - start
예제 #11
0
def bench_select(use_default):
    c = chan(0)
    cases = [
        selecting.scase(c, 1),
        selecting.rcase(c),
        selecting.scase(c, 1),
        selecting.rcase(c),
    ]
    if use_default:
        cases.append(selecting.dcase())

    def sender():
        while True:
            c.send(0)
            c.recv()
    go(sender)

    start = time.clock()
    for _ in range(QUEUE_LEN):
        selecting.select(cases)
    end = time.clock()
    return end - start
예제 #12
0
def bench_select(use_default):
    c = chan(0)
    cases = [
        selecting.scase(c, 1),
        selecting.rcase(c),
        selecting.scase(c, 1),
        selecting.rcase(c),
    ]
    if use_default:
        cases.append(selecting.dcase())

    def sender():
        while True:
            c.send(0)
            c.recv()

    go(sender)

    start = time.clock()
    for _ in range(QUEUE_LEN):
        selecting.select(cases)
    end = time.clock()
    return end - start
예제 #13
0
 def func():
     for num in range(5):
         resultschan.send(square(num))
     endchan.send()
예제 #14
0
 def func():
     for _ in range(QUEUE_LEN):
         c.send(0)
     c.close()
예제 #15
0
 def func():
     for _ in range(QUEUE_LEN):
         c.send(0)
     c.close()
예제 #16
0
 def func():
     for num in range(5):
         resultschan.send(square(num))
     endchan.send()