示例#1
0
 def fn():
     t = time.time()
     yield tap.Sleep(0.01)
     assert time.time() - t > 0.01
     t = time.time()
     yield tap.Sleep(0)
     assert time.time() - t < 0.01
    def fn():
        yield tap.CallFork(acquire)
        t = yield tap.CallFork(acquire)
        yield tap.CallFork(acquire)
        yield tap.Sleep(0)
        assert a == 5

        yield tap.Cancel(t)
        yield tap.Broadcast("unlock")
        yield tap.Sleep(0.01)
        assert a == 10

        yield tap.Broadcast("unlock")
        yield tap.Sleep(0.001)
        assert a == 10
 def fn():
     assert not q.has_work()
     t = yield tap.Fork(q.Put(3))
     yield tap.Sleep(0.01)
     assert q.has_work()
     assert (yield q.Get()) == 3
     yield tap.Join(t)
    def fn():
        yield tap.CallFork(waits)
        yield tap.CallFork(nowaits)
        yield tap.CallFork(nowaits)
        yield tap.Sleep(0)
        assert a == 5

        # the waiting strand finally gets to acquire lock, but it is the latest
        yield tap.Broadcast("msg")
        yield tap.Sleep(0)
        assert a == 6

        yield tap.Broadcast("unlock")
        yield tap.Sleep(0.01)
        assert a == 11

        yield tap.Broadcast("unlock")
        yield tap.Sleep(0.01)
        assert a == 13
    def fn():
        t1 = yield tap.CallFork(acquire, (1, None))
        t2 = yield tap.CallFork(acquire, (2, t1))
        t3 = yield tap.CallFork(acquire, (3, None))
        yield tap.Broadcast("2")
        yield tap.Broadcast("1")
        yield tap.Sleep(0.001)
        assert a == 5
        yield tap.Broadcast("3")
        yield tap.Broadcast(
            "2")  # this simultaneously tries to cancel 1 and unlocks

        yield tap.Sleep(0.01)
        assert a == 10

        yield tap.Broadcast("1")
        # 1 gets canceled after the acquire, so it's too late to release
        yield tap.Sleep(0.001)
        assert a == 10
        # yield tap.Join([t1, t2, t3])
        yield tap.Cancel(t3)
 def fn():
     t = yield tap.Fork(
         tap.Sequence([
             tap.CallThread(thread_fn),
             tap.CallThread(thread_fn),
         ]))
     yield tap.Sleep(0.01)
     assert a == 0
     with cv:
         cv.notify()
         cv.wait()
     assert a == 1
     # this cancels the second one, but not the first
     yield tap.Cancel(t)
     with cv:
         cv.notify()
         cv.wait()
     assert a == 2
     with cv:
         cv.notify()
     yield tap.Sleep(0.1)
     assert a == 2
    def fn():
        assert not q.has_work()
        t1 = yield tap.CallFork(pop_and_add)
        t2 = yield tap.CallFork(pop_and_add)
        t3 = yield tap.CallFork(pop_and_add)
        yield tap.Sleep(0)
        assert a == 0
        yield q.Put(3)
        assert a == 3

        yield tap.Cancel(t2)
        yield q.Put(5)
        assert a == 8

        yield q.Put(5)
        assert a == 8

        t4 = yield tap.CallFork(pop_and_add)
        yield tap.Sleep(0)
        assert a == 13

        yield tap.Join([t1, t3, t4])
    def fn():
        yield q.Put(3)
        t1 = yield tap.CallFork(put, (5, ))
        t2 = yield tap.CallFork(put, (7, ))
        yield tap.Sleep(0)
        assert (yield q.Get()) == 3
        assert (yield q.Get()) == 5
        yield tap.Cancel(t2)  # too late
        assert (yield q.Get()) == 7
        yield tap.Join([t1])

        t = yield tap.Fork(q.Get())
        yield q.Put(3)
        assert (yield tap.Join(t)) == 3
    def fn():
        yield q.Put(3)
        t1 = yield tap.CallFork(put, (5, ))
        t2 = yield tap.CallFork(put, (7, ))
        t3 = yield tap.CallFork(put, (9, ))
        yield tap.Sleep(0)
        assert (yield q.Get()) == 3
        yield tap.Cancel(t2)  # not too late to cancel
        assert (yield q.Get()) == 5
        assert (yield q.Get()) == 9
        yield tap.Join([t1, t3])

        t = yield tap.Fork(q.Get())
        yield q.Put(3)
        assert (yield tap.Join(t)) == 3
示例#10
0
    def fn():
        t = yield tap.Fork(tap.CallThread(thread_fn))
        yield tap.Sleep(0.01)
        assert a == 0
        with cv:
            cv.notify()
            cv.wait()
        assert a == 1
        with cv:
            cv.notify()
            cv.wait()
        assert a == 2
        with cv:
            cv.notify()
        assert a == 2

        assert (yield tap.Join(t)) == "done"
示例#11
0
 def fn():
     winner, r = yield tap.Race(
         dict(long=tap.Sleep(0.03), short=tap.Sleep(0.02)))
     assert winner == "short"
示例#12
0
 def fn():
     t = yield tap.CallFork(acquire)
     yield tap.Sleep(0.001)
     yield tap.Cancel(t)
     t = yield tap.CallFork(acquire)
     yield tap.Sleep(0.001)