示例#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()