예제 #1
0
def test_RLocker():
    wl = RWMutex()
    rl = wl.RLocker()
    wlocked = makechan(1)
    rlocked = makechan(1)

    n = 10

    def test():
        for i in range(n):
            rl.lock()
            rl.lock()
            rlocked.send(True)
            wl.lock()
            wlocked.send(True)

    @maintask
    def main():
        go(test)
        for i in range(n):
            rlocked.recv()
            rl.unlock()
            ret = select(wlocked.if_recv(), default)
            assert ret != wlocked.if_recv(), "RLocker didn't read-lock it"
            rl.unlock()
            wlocked.recv()
            ret = select(rlocked.if_recv(), default)
            assert ret != rlocked.if_recv(), "RLocker didn't respect the write lock"
            wl.unlock()

    run()
예제 #2
0
 def main():
     X, Y = makechan(), makechan()
     go(nest, X, Y)
     X.send(13)
     dprint('tnp ==== 2')
     res = Y.recv()
     dprint('tnp ==== 3')
     assert res == 13
     if SHOW_STRANGE:
         raise Exception('force prints')
예제 #3
0
 def main():
     X, Y = makechan(), makechan()
     go(nest, X, Y)
     X.send(13)
     dprint('tnp ==== 2')
     res = Y.recv()
     dprint('tnp ==== 3')
     assert res == 13
     if SHOW_STRANGE:
         raise Exception('force prints')
예제 #4
0
    def main():
        c = makechan(5, label="c")
        quit = makechan(label="quit")
        def f():
            for i in range(5):
                v = c.recv()
                rlist.append(v)
            quit.send(0)

        go(f)
        test(c, quit)
예제 #5
0
def main():
    c = makechan()
    quit = makechan()
    def f():
        for i in range(10):
            print(c.recv())

        quit.send(0)

    go(f)
    fibonacci(c, quit)
예제 #6
0
    def main():
        c = makechan()
        quit = makechan()
        def f():
            for i in range(10):
                rlist.append(c.recv())
            print(rlist)
            quit.send(0)

        go(f)
        fibonacci(c, quit)
예제 #7
0
    def main():
        c = makechan()
        quit = makechan()

        def f():
            for i in range(10):
                rlist.append(c.recv())
            print(rlist)
            quit.send(0)

        go(f)
        fibonacci(c, quit)
예제 #8
0
 def nest(X, Y):
     X2, Y2 = makechan(), makechan()
     go(pipe, X2, Y2)
     dprint('tnp_N ==== 1')
     X_Val = X.recv()
     dprint('tnp_N ==== 2')
     X2.send(X_Val)
     dprint('tnp_N ==== 3')
     Y2_Val = Y2.recv()
     dprint('tnp_N ==== 4')
     Y.send(Y2_Val)
     dprint('tnp_N ==== 5')
예제 #9
0
    def main():
        c = makechan(5, label="c")
        quit = makechan(label="quit")

        def f():
            for i in range(5):
                v = c.recv()
                rlist.append(v)
            quit.send(0)

        go(f)
        test(c, quit)
예제 #10
0
 def nest(X, Y):
     X2, Y2 = makechan(), makechan()
     go(pipe, X2, Y2)
     dprint('tnp_N ==== 1')
     X_Val = X.recv()
     dprint('tnp_N ==== 2')
     X2.send(X_Val)
     dprint('tnp_N ==== 3')
     Y2_Val = Y2.recv()
     dprint('tnp_N ==== 4')
     Y.send(Y2_Val)
     dprint('tnp_N ==== 5')
예제 #11
0
def main():
    c = makechan()
    quit = makechan()

    def f():
        for i in range(10):
            print(c.recv())

        quit.send(0)

    go(f)
    fibonacci(c, quit)
예제 #12
0
        def main():
            X, Y = makechan(), makechan()
            Ret_chan = makechan()

            go(wait_two, X, Y, Ret_chan)

            dprint('twt ==== 1')
            Y.send(42)

            dprint('twt ==== 2')
            X.send(42)
            dprint('twt ==== 3')
            value = Ret_chan.recv()
            dprint('twt ==== 4')
            assert value == (2, 42)
예제 #13
0
        def main():
            X, Y = makechan(), makechan()
            Ret_chan = makechan()

            go(wait_two, X, Y, Ret_chan)

            dprint('twt ==== 1')
            Y.send(42)

            dprint('twt ==== 2')
            X.send(42)
            dprint('twt ==== 3')
            value = Ret_chan.recv()
            dprint('twt ==== 4')
            assert value == (2, 42)
예제 #14
0
def main():
    print(current)
    c = makechan(1)
    signal.notify(c, os.SIGINT, os.SIGTERM, os.SIGQUIT)
    s = c.recv()
    print("got signal: %s" % s)
    print(kernel.runq)
예제 #15
0
def test_Cond_broadcast():
    m = Mutex()
    c = Cond(m)
    n = 200
    running = makechan(n)
    awake = makechan(n)
    exit = False

    def test(i):
        m.lock()
        while not exit:
            running.send(i)
            c.wait()
            awake.send(i)
        m.unlock()

    @maintask
    def main():
        for i in range(n):
            go(test, i)

        for i in range(n):
            for i in range(n):
                running.recv()
            if i == n -1:
                m.lock()
                exit = True
                m.unlock()

            ret = select(awake.if_recv(), default)
            assert ret != awake.if_recv(), "coroutine not asleep"

            m.lock()
            c.broadcast()
            m.unlock()

            seen = {}
            for i in range(n):
                g = awake.recv()
                assert g not in seen, "coroutine woke up twice"
                seen[g] = True

        ret = select(running.if_recv(), default)
        assert ret != running.if_recv(), "coroutine did not exist"
        c.broadcast()

    run()
예제 #16
0
    def main():
        c = makechan(5, label="c")
        go(test, c)

        for i in range(5):
            c.send(i)

        c.send("QUIT")
예제 #17
0
        def main():
            ch = makechan()

            for each in numbers:
                go(counter, each, ch)

            for each in numbers:
                ch.send(None)
예제 #18
0
    def main():
        c = makechan(5, label="c")
        go(test, c)

        for i in range(5):
            c.send(i)

        c.send("QUIT")
예제 #19
0
        def main():
            ch = makechan()

            for each in numbers:
                go(counter, each, ch)

            for each in numbers:
                ch.send(None)
예제 #20
0
    def test_readers(num):
        m = RWMutex()
        clocked = makechan()
        cunlock = makechan()
        cdone = makechan()

        for i in range(num):
            go(reader, m, clocked, cunlock, cdone)

        for i in range(num):
            clocked.recv()

        for i in range(num):
            cunlock.send(True)

        for i in range(num):
            cdone.recv()
예제 #21
0
    def main():
        m = Mutex()
        c = Cond(m)
        n = 100
        running = makechan(n)
        awake = makechan(n)

        for i in range(n):
            go(test, i, m, c, running, awake)

            if i > 0:
                a = awake.recv()
                assert a == (i - 1), "wrong coroutine woke up: want %d, got %d" % (i-1, a)

            running.recv()
            with m:
                c.signal()
예제 #22
0
    def main():
        m = Mutex()
        c = makechan()
        for i in range(10):
            go(hammer_mutex, m, 1000, c)

        for i in range(10):
            c.recv()
예제 #23
0
        def main():
            c = makechan(10)

            go(sender, c)
            unblocked_recv = []
            for i in range(11):
                unblocked_recv.append(c.recv())

            assert len(unblocked_recv) == 11
예제 #24
0
def main():
    a = [7, 2, 8, -9, 4, 0]

    c = makechan()
    go(sum, a[:int(len(a) / 2)], c)
    go(sum, a[int(len(a) / 2):], c)
    x, y = c.recv(), c.recv()

    print(x, y, x + y)
예제 #25
0
def main():
    a = [7, 2, 8, -9, 4, 0]

    c = makechan()
    go(sum, a[:int(len(a)/2)], c)
    go(sum, a[int(len(a)/2):], c)
    x, y = c.recv(), c.recv()

    print(x, y, x+y)
예제 #26
0
        def main():
            c = makechan(10)

            go(sender, c)
            unblocked_recv = []
            for i in range(11):
                unblocked_recv.append(c.recv())


            assert len(unblocked_recv) == 11
예제 #27
0
    def main():
        c = makechan()
        once = Once()
        o = AtomicLong(0)
        for i in range(10):
            go(test, once, o, c)

        for i in range(10):
            c.recv()

        assert o == 1
예제 #28
0
 def wait_two(X, Y, Ret_chan):
     Barrier = makechan()
     go(sleep, X, Barrier)
     go(sleep, Y, Barrier)
     dprint('twt_W ==== 1')
     ret = Barrier.recv()
     dprint('twt_W ==== 2')
     if ret[0] == X:
         Ret_chan.send((1, ret[1]))
     else:
         Ret_chan.send((2, ret[1]))
     dprint('twt_W ==== 3')
예제 #29
0
 def wait_two(X, Y, Ret_chan):
     Barrier = makechan()
     go(sleep, X, Barrier)
     go(sleep, Y, Barrier)
     dprint('twt_W ==== 1')
     ret = Barrier.recv()
     dprint('twt_W ==== 2')
     if ret[0] == X:
         Ret_chan.send((1, ret[1]))
     else:
         Ret_chan.send((2, ret[1]))
     dprint('twt_W ==== 3')
예제 #30
0
        def main():
            c = makechan(100)

            unblocked_sent = 0
            for i in range(100):
                c.send(True)
                unblocked_sent += 1

            assert unblocked_sent == 100

            unblocked_recv = []
            for i in range(100):
                unblocked_recv.append(c.recv())

            assert len(unblocked_recv) == 100
예제 #31
0
    def main():
        m = Mutex()
        c = Cond(m)
        n = 2
        running = makechan(n)
        awake = makechan(n)

        for i in range(n):
            go(test, m, c, running, awake)

        for i in range(n):
            running.recv()

        while n > 0:
            ret = select(awake.if_recv(), default)
            assert ret != awake.if_recv(), "coroutine not asleep"

            m.lock()
            c.signal()
            awake.recv()
            ret = select(awake.if_recv(), default)
            assert ret != awake.if_recv(), "too many coroutines awakes"
            n -= 1
        c.signal()
예제 #32
0
        def main():
            c = makechan(100)

            unblocked_sent = 0
            for i in range(100):
                c.send(True)
                unblocked_sent += 1

            assert unblocked_sent == 100

            unblocked_recv = []
            for i in range(100):
                unblocked_recv.append(c.recv())

            assert len(unblocked_recv) == 100
예제 #33
0
파일: test_time.py 프로젝트: AtillaE/offset
    def main():
        i = 10
        c = makechan()

        def f():
            i -= 1
            if i >= 0:
                AfterFunc(0, f)
                sleep(1 * SECOND)
            else:
                c.send(True)

        AfterFunc(0, f)
        c.recv()

        assert i == 0
예제 #34
0
    def main():
        i = 10
        c = makechan()

        def f():
            i -= 1
            if i >= 0:
                AfterFunc(0, f)
                sleep(1 * SECOND)
            else:
                c.send(True)

        AfterFunc(0, f)
        c.recv()

        assert i == 0
예제 #35
0
    def hammer_rwmutex(num_readers, num_iterations):
        activity = AtomicLong(0)
        rwm = RWMutex()
        cdone = makechan()

        go(writer, rwm, num_iterations, activity, cdone)

        for i in range(int(num_readers / 2)):
            go(reader, rwm, num_iterations, activity, cdone)

        go(writer, rwm, num_iterations, activity, cdone)

        for i in range(num_readers):
            go(reader, rwm, num_iterations, activity, cdone)

        for i in range(2 + num_readers):
            cdone.recv()
예제 #36
0
    def test_offset(self):

        wait = WaitGroup()
        channel = makechan()

        def go_wait(func, *args, **kwargs):
            wait.add(1)
            go(func, *args, **kwargs)

        def search(provider, term):

            print 'searching with %r' % provider

            results = provider.search(term, streaming=True)

            for result in results:
                channel.send(result)
                sleep(SECOND)

            print 'done searching with %r' % provider
            wait.done()

        @maintask
        def main():

            play = GooglePlayMovies()
            itunes = AppleITunesMovies()

            go_wait(search, play, 'terminator')
            go_wait(search, itunes, 'terminator')

            while wait.counter > 0:
                result = channel.recv()
                print 'received %r' % result._asdict()

            wait.wait()

        run()
예제 #37
0
    def test_offset(self):

        wait = WaitGroup()
        channel = makechan()

        def go_wait(func, *args, **kwargs):
            wait.add(1)
            go(func, *args, **kwargs)

        def search(provider, term):

            print 'searching with %r' % provider

            results = provider.search(term, streaming=True)

            for result in results:
                channel.send(result)
                sleep(SECOND)

            print 'done searching with %r' % provider
            wait.done()

        @maintask
        def main():

            play = GooglePlayMovies()
            itunes = AppleITunesMovies()

            go_wait(search, play, 'terminator')
            go_wait(search, itunes, 'terminator')

            while wait.counter > 0:
                result = channel.recv()
                print 'received %r' % result._asdict()

            wait.wait()

        run()
예제 #38
0
    def test_waitgroup(wg1, wg2):
        n = 16
        wg1.add(n)
        wg2.add(n)
        exited = makechan(n)

        def f(i):
            wg1.done()
            wg2.wait()
            exited.send(True)

        for i in range(n):
            go(f, i)

        wg1.wait()

        for i in range(n):
            ret = select(exited.if_recv(), default)
            assert ret != exited.if_recv(), "WaitGroup released group too soon"
            wg2.done()

            for i in range(16):
                exited.recv()
예제 #39
0
def main():
    c = makechan(2)
    c.send(1)
    c.send(2)
    print(c.recv())
    print(c.recv())
예제 #40
0
 def main():
     c = makechan()
     go(f, c)
     go(f1, c)
     go(f2, c)
예제 #41
0
 def main():
     ch = makechan()
     for each in numbers:
         go(counter, each, ch)
     for each in numbers:
         rlist.append(ch.recv())
예제 #42
0
 def main():
     ch = makechan()
     go(sending, ch)
     go(receiving, ch)
예제 #43
0
 def main():
     ch = makechan()
     go(sending, ch)
     go(receiving, ch)
예제 #44
0
 def main():
     ch = makechan()
     for each in numbers:
         go(counter, each, ch)
     for each in numbers:
         rlist.append(ch.recv())
예제 #45
0
        def main():
            X, Y = makechan(), makechan()
            go(pipe, X, Y)

            X.send(42)
            assert Y.recv() == 42
예제 #46
0
 def main():
     chan = makechan()
     go(exp_recv, chan)
     go(exp_sender, chan)
예제 #47
0
 def main():
     c = makechan()
     go(f, c)
     go(f1, c)
     go(f2, c)
예제 #48
0
        def main():
            X, Y = makechan(), makechan()
            go(pipe, X, Y)

            X.send(42)
            assert Y.recv() == 42
예제 #49
0
 def main():
     chan = makechan()
     go(exp_recv, chan)
     go(exp_sender, chan)