예제 #1
0
    def f():
        yield a._start()
        yield b._start()
        while len(c.ncores) < 2:
            yield gen.sleep(0.01)

        try:
            e1 = Executor((c.ip, c.port), start=False, loop=loop)
            yield e1._start()
            e2 = Executor(e1.scheduler, start=False, loop=loop)
            yield e2._start()

            x = e1.submit(inc, 1)
            y = e2.submit(inc, 2)
            xx = yield x._result()
            yy = yield y._result()
            assert xx == 2
            assert yy == 3

            yield e1._restart()

            assert x.cancelled()
            assert y.cancelled()
        finally:
            yield a._close()
            yield b._close()
            yield e1._shutdown(fast=True)
            yield e2._shutdown(fast=True)
            c.stop()
예제 #2
0
    def f():
        yield a._start()
        yield b._start()
        while len(c.ncores) < 2:
            yield gen.sleep(0.01)

        try:
            e1 = Executor((c.ip, c.port), start=False, loop=loop)
            yield e1._start()
            e2 = Executor(scheduler=e1.scheduler, start=False, loop=loop)
            yield e2._start()

            x = e1.submit(inc, 1)
            y = e2.submit(inc, 2)
            xx = yield x._result()
            yy = yield y._result()
            assert xx == 2
            assert yy == 3

            yield e1._restart()

            assert x.cancelled()
            assert y.cancelled()
        finally:
            yield a._close()
            yield b._close()
            yield e1._shutdown(fast=True)
            yield e2._shutdown(fast=True)
            c.stop()
예제 #3
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)

        assert a.event is b.event

        c = e.submit(inc, 1, pure=False)
        assert c.key != a.key
예제 #4
0
def test_submit_errors(loop):
    def f(a, b, c):
        pass

    e = Executor('127.0.0.1:8787', start=False, loop=loop)

    with pytest.raises(TypeError):
        e.submit(1, 2, 3)
    with pytest.raises(TypeError):
        e.map([1, 2, 3])
예제 #5
0
def test_submit_errors():
    def f(a, b, c):
        pass

    e = Executor('127.0.0.1:8787', start=False)

    with pytest.raises(TypeError):
        e.submit(1, 2, 3)
    with pytest.raises(TypeError):
        e.map([1, 2, 3])
예제 #6
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)

        assert a.event is b.event

        c = e.submit(inc, 1, pure=False)
        assert c.key != a.key
예제 #7
0
def test_Future_exception(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(div, 1, 0)
    result = yield x._exception()
    assert isinstance(result, ZeroDivisionError)

    x = e.submit(div, 1, 1)
    result = yield x._exception()
    assert result is None
    yield e._shutdown()
예제 #8
0
def test_Future_exception(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(div, 1, 0)
    result = yield x._exception()
    assert isinstance(result, ZeroDivisionError)

    x = e.submit(div, 1, 1)
    result = yield x._exception()
    assert result is None
    yield e._shutdown()
예제 #9
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(div, 1, 0)
        result = yield x._exception()
        assert isinstance(result, ZeroDivisionError)

        x = e.submit(div, 1, 1)
        result = yield x._exception()
        assert result is None
        yield e._shutdown()
예제 #10
0
def test_submit_naming(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    a = e.submit(inc, 1)
    b = e.submit(inc, 1)

    assert a.event is b.event

    c = e.submit(inc, 1, pure=False)
    assert c.key != a.key

    yield e._shutdown()
예제 #11
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(identity, 1, workers=[a.address[0]])
        y = e.submit(identity, tuple(range(100)), workers=[b.address[0]])
        yield e._gather([x, y])

        z = e.submit(lambda x, y: None, x, y)
        yield z._result()
        assert e.scheduler.who_has[z.key] == {b.address}

        yield e._shutdown()
예제 #12
0
def test_nbytes_determines_worker(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(identity, 1, workers=[a.address[0]])
    y = e.submit(identity, tuple(range(100)), workers=[b.address[0]])
    yield e._gather([x, y])

    z = e.submit(lambda x, y: None, x, y)
    yield z._result()
    assert s.who_has[z.key] == {b.address}

    yield e._shutdown()
예제 #13
0
def test_submit_naming(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    a = e.submit(inc, 1)
    b = e.submit(inc, 1)

    assert a.event is b.event

    c = e.submit(inc, 1, pure=False)
    assert c.key != a.key

    yield e._shutdown()
예제 #14
0
def test_nbytes_determines_worker(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(identity, 1, workers=[a.address[0]])
    y = e.submit(identity, tuple(range(100)), workers=[b.address[0]])
    yield e._gather([x, y])

    z = e.submit(lambda x, y: None, x, y)
    yield z._result()
    assert s.who_has[z.key] == {b.address}

    yield e._shutdown()
예제 #15
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)
        x = e.submit(inc, 10)
        y = e.submit(inc, x)

        result = yield e._gather(x)
        assert result == 11
        result = yield e._gather([x])
        assert result == [11]
        result = yield e._gather({'x': x, 'y': [y]})
        assert result == {'x': 11, 'y': [12]}

        yield e._shutdown()
예제 #16
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)
        x = e.submit(inc, 10)
        y = e.submit(inc, x)

        result = yield e._gather(x)
        assert result == 11
        result = yield e._gather([x])
        assert result == [11]
        result = yield e._gather({'x': x, 'y': [y]})
        assert result == {'x': 11, 'y': [12]}

        yield e._shutdown()
예제 #17
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)
        c = e.submit(inc, 2)

        done, not_done = yield _wait([a, b, c])

        assert done == {a, b, c}
        assert not_done == set()
        assert a.status == b.status == 'finished'

        yield e._shutdown()
예제 #18
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)
        c = e.submit(inc, 2)

        done, not_done = yield _wait([a, b, c])

        assert done == {a, b, c}
        assert not_done == set()
        assert a.status == b.status == 'finished'

        yield e._shutdown()
예제 #19
0
def test_gather(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(inc, 10)
    y = e.submit(inc, x)

    result = yield e._gather(x)
    assert result == 11
    result = yield e._gather([x])
    assert result == [11]
    result = yield e._gather({'x': x, 'y': [y]})
    assert result == {'x': 11, 'y': [12]}

    yield e._shutdown()
예제 #20
0
def test_wait(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    a = e.submit(inc, 1)
    b = e.submit(inc, 1)
    c = e.submit(inc, 2)

    done, not_done = yield _wait([a, b, c])

    assert done == {a, b, c}
    assert not_done == set()
    assert a.status == b.status == 'finished'

    yield e._shutdown()
예제 #21
0
def test_wait(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    a = e.submit(inc, 1)
    b = e.submit(inc, 1)
    c = e.submit(inc, 2)

    done, not_done = yield _wait([a, b, c])

    assert done == {a, b, c}
    assert not_done == set()
    assert a.status == b.status == 'finished'

    yield e._shutdown()
예제 #22
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)
        c = e.submit(inc, 2)

        done, not_done = yield _wait([a, b, c])

        assert done == {a, b, c}
        assert not_done == set()
        assert a.status == b.status == 'finished'

        yield e._shutdown()
예제 #23
0
def test_gather(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(inc, 10)
    y = e.submit(inc, x)

    result = yield e._gather(x)
    assert result == 11
    result = yield e._gather([x])
    assert result == [11]
    result = yield e._gather({'x': x, 'y': [y]})
    assert result == {'x': 11, 'y': [12]}

    yield e._shutdown()
예제 #24
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(inc, 10)
        y = e.submit(inc, x)

        result = yield e._gather(x)
        assert result == 11
        result = yield e._gather([x])
        assert result == [11]
        result = yield e._gather({'x': x, 'y': [y]})
        assert result == {'x': 11, 'y': [12]}

        yield e._shutdown()
예제 #25
0
def test__as_completed(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    a = e.submit(inc, 1)
    b = e.submit(inc, 1)
    c = e.submit(inc, 2)

    from distributed.compatibility import Queue
    queue = Queue()
    yield _as_completed([a, b, c], queue)

    assert queue.qsize() == 3
    assert {queue.get(), queue.get(), queue.get()} == {a, b, c}

    yield e._shutdown()
예제 #26
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)
        c = e.submit(inc, 2)

        from distributed.compatibility import Queue
        queue = Queue()
        yield _as_completed([a, b, c], queue)

        assert queue.qsize() == 3
        assert {queue.get(), queue.get(), queue.get()} == {a, b, c}

        yield e._shutdown()
예제 #27
0
def test__scatter(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    d = yield e._scatter({'y': 20})
    assert isinstance(d['y'], Future)
    assert a.data.get('y') == 20 or b.data.get('y') == 20
    assert (a.address in s.who_has['y'] or
            b.address in s.who_has['y'])
    assert s.who_has['y']
    assert s.nbytes == {'y': sizeof(20)}
    yy = yield e._gather([d['y']])
    assert yy == [20]

    [x] = yield e._scatter([10])
    assert isinstance(x, Future)
    assert a.data.get(x.key) == 10 or b.data.get(x.key) == 10
    xx = yield e._gather([x])
    assert s.who_has[x.key]
    assert (a.address in s.who_has[x.key] or
            b.address in s.who_has[x.key])
    assert s.nbytes == {'y': sizeof(20), x.key: sizeof(10)}
    assert xx == [10]

    z = e.submit(add, x, d['y'])  # submit works on RemoteData
    result = yield z._result()
    assert result == 10 + 20
    result = yield e._gather([z, x])
    assert result == [30, 10]

    yield e._shutdown()
예제 #28
0
def test_exception_on_exception(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(lambda: 1 / 0)
    y = e.submit(inc, x)

    with pytest.raises(ZeroDivisionError):
        out = yield y._result()

    z = e.submit(inc, y)

    with pytest.raises(ZeroDivisionError):
        out = yield z._result()

    yield e._shutdown()
예제 #29
0
def test_map_on_futures_with_kwargs(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    def f(x, y=10):
        return x + y

    futures = e.map(inc, range(10))
    futures2 = e.map(f, futures, y=20)
    results = yield e._gather(futures2)
    assert results == [i + 1 + 20 for i in range(10)]

    future = e.submit(inc, 100)
    future2 = e.submit(f, future, y=200)
    result = yield future2._result()
    assert result == 100 + 1 + 200
예제 #30
0
def test_map_on_futures_with_kwargs(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    def f(x, y=10):
        return x + y

    futures = e.map(inc, range(10))
    futures2 = e.map(f, futures, y=20)
    results = yield e._gather(futures2)
    assert results == [i + 1 + 20 for i in range(10)]

    future = e.submit(inc, 100)
    future2 = e.submit(f, future, y=200)
    result = yield future2._result()
    assert result == 100 + 1 + 200
예제 #31
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)
        c = e.submit(inc, 2)

        from distributed.compatibility import Queue
        queue = Queue()
        yield _as_completed([a, b, c], queue)

        assert queue.qsize() == 3
        assert {queue.get(), queue.get(), queue.get()} == {a, b, c}

        yield e._shutdown()
예제 #32
0
    def f():
        yield a._start()
        yield b._start()

        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()
        assert e.scheduler.ncores == {a.worker_address: 2, b.worker_address: 2}

        x = e.submit(inc, 1)
        y = e.submit(inc, x)
        yield y._result()

        cc = rpc(ip=c.ip, port=c.port)
        who_has = yield cc.who_has()
        try:
            assert e.scheduler.who_has == who_has
            assert set(e.scheduler.who_has) == {x.key, y.key}

            yield e._restart()

            assert len(e.scheduler.stacks) == 2
            assert len(e.scheduler.processing) == 2

            who_has = yield cc.who_has()
            assert not who_has
            assert not e.scheduler.who_has

            assert x.cancelled()
            assert y.cancelled()

        finally:
            yield a._close()
            yield b._close()
            yield e._shutdown(fast=True)
            c.stop()
예제 #33
0
def test_exception_on_exception(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(lambda: 1 / 0)
    y = e.submit(inc, x)

    with pytest.raises(ZeroDivisionError):
        out = yield y._result()

    z = e.submit(inc, y)

    with pytest.raises(ZeroDivisionError):
        out = yield z._result()

    yield e._shutdown()
예제 #34
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        a = e.submit(inc, 1)
        b = e.submit(inc, 1)
        c = e.submit(inc, 2)

        from distributed.compatibility import Queue
        queue = Queue()
        yield _as_completed([a, b, c], queue)

        assert queue.qsize() == 3
        assert {queue.get(), queue.get(), queue.get()} == {a, b, c}

        yield e._shutdown()
예제 #35
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        d = yield e._scatter({'y': 20})
        assert isinstance(d['y'], Future)
        assert a.data.get('y') == 20 or b.data.get('y') == 20
        assert (a.address in e.scheduler.who_has['y'] or
                b.address in e.scheduler.who_has['y'])
        assert c.who_has['y']
        assert e.scheduler.nbytes == {'y': sizeof(20)}
        yy = yield e._gather([d['y']])
        assert yy == [20]

        [x] = yield e._scatter([10])
        assert isinstance(x, Future)
        assert a.data.get(x.key) == 10 or b.data.get(x.key) == 10
        xx = yield e._gather([x])
        assert c.who_has[x.key]
        assert (a.address in e.scheduler.who_has[x.key] or
                b.address in e.scheduler.who_has[x.key])
        assert e.scheduler.nbytes == {'y': sizeof(20), x.key: sizeof(10)}
        assert xx == [10]

        z = e.submit(add, x, d['y'])  # submit works on RemoteData
        result = yield z._result()
        assert result == 10 + 20
        result = yield e._gather([z, x])
        assert result == [30, 10]

        yield e._shutdown()
예제 #36
0
def test_future(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(inc, 10)
    assert str(x.key) in repr(x)
    assert str(x.status) in repr(x)
    yield e._shutdown()
예제 #37
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(div, 1, 2)
        result = yield x._result()
        assert result == 1 / 2

        x = e.submit(div, 1, 0)
        with pytest.raises(ZeroDivisionError):
            result = yield x._result()

        x = e.submit(div, 10, 2)  # continues to operate
        result = yield x._result()
        assert result == 10 / 2

        yield e._shutdown()
예제 #38
0
    def f(s, a, b):
        assert s.ncores == {a.address: a.ncores, b.address: b.ncores}
        e = Executor(('127.0.0.1', s.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(inc, 1)
        y = e.submit(inc, 2)
        z = e.submit(add, x, y)
        result = yield x._result()
        assert result == 1 + 1

        a, b, c = yield e._scatter([1, 2, 3])
        aa, bb, xx = yield e._gather([a, b, x])
        assert (aa, bb, xx) == (1, 2, 2)

        result = yield e._get({'x': (inc, 1), 'y': (add, 'x', 10)}, 'y')
        assert result == 12
예제 #39
0
def test_exceptions(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(div, 1, 2)
    result = yield x._result()
    assert result == 1 / 2

    x = e.submit(div, 1, 0)
    with pytest.raises(ZeroDivisionError):
        result = yield x._result()

    x = e.submit(div, 10, 2)  # continues to operate
    result = yield x._result()
    assert result == 10 / 2

    yield e._shutdown()
예제 #40
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)

        x = e.submit(lambda: 1 / 0)
        y = e.submit(inc, x)

        yield e._start()

        with pytest.raises(ZeroDivisionError):
            out = yield y._result()

        z = e.submit(inc, y)

        with pytest.raises(ZeroDivisionError):
            out = yield z._result()

        yield e._shutdown()
예제 #41
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        x = e.submit(div, 1, 2)
        result = yield x._result()
        assert result == 1 / 2

        x = e.submit(div, 1, 0)
        with pytest.raises(ZeroDivisionError):
            result = yield x._result()

        x = e.submit(div, 10, 2)  # continues to operate
        result = yield x._result()
        assert result == 10 / 2

        yield e._shutdown()
예제 #42
0
def test_map(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    L1 = e.map(inc, range(5))
    assert len(L1) == 5
    assert isdistinct(x.key for x in L1)
    assert all(isinstance(x, Future) for x in L1)

    result = yield L1[0]._result()
    assert result == inc(0)
    assert len(s.dask) == 5

    L2 = e.map(inc, L1)

    result = yield L2[1]._result()
    assert result == inc(inc(1))
    assert len(s.dask) == 10
    assert L1[0].key in s.dask[L2[0].key]

    total = e.submit(sum, L2)
    result = yield total._result()
    assert result == sum(map(inc, map(inc, range(5))))

    L3 = e.map(add, L1, L2)
    result = yield L3[1]._result()
    assert result == inc(1) + inc(inc(1))

    L4 = e.map(add, range(3), range(4))
    results = yield e._gather(L4)
    if sys.version_info[0] >= 3:
        assert results == list(map(add, range(3), range(4)))

    def f(x, y=10):
        return x + y

    L5 = e.map(f, range(5), y=5)
    results = yield e._gather(L5)
    assert results == list(range(5, 10))

    y = e.submit(f, 10)
    L6 = e.map(f, range(5), y=y)
    results = yield e._gather(L6)
    assert results == list(range(20, 25))

    yield e._shutdown()
예제 #43
0
def test_exceptions(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(div, 1, 2)
    result = yield x._result()
    assert result == 1 / 2

    x = e.submit(div, 1, 0)
    with pytest.raises(ZeroDivisionError):
        result = yield x._result()

    x = e.submit(div, 10, 2)  # continues to operate
    result = yield x._result()
    assert result == 10 / 2

    yield e._shutdown()
예제 #44
0
    def f(s, a, b):
        assert s.ncores == {a.address: a.ncores, b.address: b.ncores}
        e = Executor(('127.0.0.1', s.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(inc, 1)
        y = e.submit(inc, 2)
        z = e.submit(add, x, y)
        result = yield x._result()
        assert result == 1 + 1

        a, b, c = yield e._scatter([1, 2, 3])
        aa, bb, xx = yield e._gather([a, b, x])
        assert (aa, bb, xx) == (1, 2, 2)

        result = yield e._get({'x': (inc, 1), 'y': (add, 'x', 10)}, 'y')
        assert result == 12
예제 #45
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        L1 = e.map(inc, range(5))
        assert len(L1) == 5
        assert isdistinct(x.key for x in L1)
        assert all(isinstance(x, Future) for x in L1)

        result = yield L1[0]._result()
        assert result == inc(0)
        assert len(e.dask) == 5

        L2 = e.map(inc, L1)

        result = yield L2[1]._result()
        assert result == inc(inc(1))
        assert len(e.dask) == 10
        assert L1[0].key in e.dask[L2[0].key]

        total = e.submit(sum, L2)
        result = yield total._result()
        assert result == sum(map(inc, map(inc, range(5))))

        L3 = e.map(add, L1, L2)
        result = yield L3[1]._result()
        assert result == inc(1) + inc(inc(1))

        L4 = e.map(add, range(3), range(4))
        results = yield e._gather(L4)
        if sys.version_info[0] >= 3:
            assert results == list(map(add, range(3), range(4)))

        def f(x, y=10):
            return x + y

        L5 = e.map(f, range(5), y=5)
        results = yield e._gather(L5)
        assert results == list(range(5, 10))

        y = e.submit(f, 10)
        L6 = e.map(f, range(5), y=y)
        results = yield e._gather(L6)
        assert results == list(range(20, 25))

        yield e._shutdown()
예제 #46
0
def test_future(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(inc, 10)
    assert str(x.key) in repr(x)
    assert str(x.status) in repr(x)
    yield e._shutdown()
예제 #47
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        x = e.submit(div, 1, 2)
        result = yield x._result()
        assert result == 1 / 2

        x = e.submit(div, 1, 0)
        with pytest.raises(ZeroDivisionError):
            result = yield x._result()

        x = e.submit(div, 10, 2)  # continues to operate
        result = yield x._result()
        assert result == 10 / 2

        yield e._shutdown()
예제 #48
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False, loop=loop)
        yield e._start()

        x = e.submit(randint, 0, 1000, pure=True)
        xx = yield x._result()

        f = Executor((c.ip, c.port), start=False, loop=loop)
        yield f._start()

        y = f.submit(randint, 0, 1000, pure=True)
        yy = yield y._result()

        assert xx == yy

        yield e._shutdown()
        yield f._shutdown()
예제 #49
0
def test_sync_exceptions(loop):
    with cluster() as (s, [a, b]):
        e = Executor(('127.0.0.1', s['port']), loop=loop)

        x = e.submit(div, 10, 2)
        assert x.result() == 5

        y = e.submit(div, 10, 0)
        try:
            y.result()
            assert False
        except ZeroDivisionError:
            pass

        z = e.submit(div, 10, 5)
        assert z.result() == 2

        e.shutdown()
예제 #50
0
def test_two_consecutive_executors_share_results(s, a, b):
    from random import randint
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(randint, 0, 1000, pure=True)
    xx = yield x._result()

    f = Executor((s.ip, s.port), start=False)
    yield f._start()

    y = f.submit(randint, 0, 1000, pure=True)
    yy = yield y._result()

    assert xx == yy

    yield e._shutdown()
    yield f._shutdown()
예제 #51
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        x = e.submit(randint, 0, 1000, pure=True)
        xx = yield x._result()

        f = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(f._go)
        yield f._sync_center()

        y = f.submit(randint, 0, 1000, pure=True)
        yy = yield y._result()

        assert xx == yy

        yield e._shutdown()
        yield f._shutdown()
예제 #52
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        x = e.submit(assert_list, [1, 2, 3], z=[4, 5, 6])
        result = yield x._result()
        assert result

        yield e._shutdown()
예제 #53
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)
        x = e.submit(inc, 10)
        assert not x.done()

        assert isinstance(x, Future)
        assert x.executor is e
        result = yield x._result()
        assert result == 11
        assert x.done()

        y = e.submit(inc, 20)
        z = e.submit(add, x, y)
        result = yield z._result()
        assert result == 11 + 21
        yield e._shutdown()
        assert c.who_has[z.key]
예제 #54
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        x = e.submit(assert_list, [1, 2, 3], z=[4, 5, 6])
        result = yield x._result()
        assert result

        yield e._shutdown()
예제 #55
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(e._go)

        x = e.submit(randint, 0, 1000, pure=True)
        xx = yield x._result()

        f = Executor((c.ip, c.port), start=False)
        IOLoop.current().spawn_callback(f._go)
        yield f._sync_center()

        y = f.submit(randint, 0, 1000, pure=True)
        yy = yield y._result()

        assert xx == yy

        yield e._shutdown()
        yield f._shutdown()
예제 #56
0
def test_remote_submit_on_Future(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(lambda x: x + 1, 1)
    y = e.submit(lambda x: x + 1, x)
    result = yield y._result()
    assert result == 3

    yield e._shutdown()
예제 #57
0
    def f(c, a, b):
        e = Executor((c.ip, c.port), start=False,
                loop=loop)
        yield e._start()

        from time import sleep
        x = e.submit(sleep, 3)
        yield x._result()

        yield e._shutdown()
예제 #58
0
def test_submit(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(inc, 10)
    assert not x.done()

    assert isinstance(x, Future)
    assert x.executor is e
    result = yield x._result()
    assert result == 11
    assert x.done()

    y = e.submit(inc, 20)
    z = e.submit(add, x, y)
    result = yield z._result()
    assert result == 11 + 21
    yield e._shutdown()
    assert s.who_has[z.key]
예제 #59
0
def test_many_submits_spread_evenly(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    L = [e.submit(inc, i) for i in range(10)]
    yield _wait(L)

    assert a.data and b.data

    yield e._shutdown()
예제 #60
0
def test_aliases(s, a, b):
    e = Executor((s.ip, s.port), start=False)
    yield e._start()

    x = e.submit(inc, 1)

    dsk = {'y': x}
    result = yield e._get(dsk, 'y')
    assert result == 2

    yield e._shutdown()