Ejemplo n.º 1
0
def test_err_on_bad_deserializer():
    frames = yield to_frames({"x": to_serialize(1234)}, serializers=["pickle"])

    result = yield from_frames(frames, deserializers=["pickle", "foo"])
    assert result == {"x": 1234}

    with pytest.raises(TypeError) as info:
        yield from_frames(frames, deserializers=["msgpack"])
Ejemplo n.º 2
0
def test_err_on_bad_deserializer():
    frames = yield to_frames({'x': to_serialize(1234)}, serializers=['pickle'])

    result = yield from_frames(frames, deserializers=['pickle', 'foo'])
    assert result == {'x': 1234}

    with pytest.raises(TypeError) as info:
        yield from_frames(frames, deserializers=['msgpack'])
Ejemplo n.º 3
0
def test_err_on_bad_deserializer():
    frames = yield to_frames({'x': to_serialize(1234)},
                                     serializers=['pickle'])

    result = yield from_frames(frames, deserializers=['pickle', 'foo'])
    assert result == {'x': 1234}

    with pytest.raises(TypeError) as info:
        yield from_frames(frames, deserializers=['msgpack'])
Ejemplo n.º 4
0
def server(env, port, func, enable_rmm, num_workers, proc_conn):
    # create frames to send
    # create listener
    # notify parent process of listener status
    # write object to each new connection for TRANSFER_ITERATIONS
    # close listener after num_workers*EP_ITERATIONS have disconnected

    os.environ.update(env)

    loop = asyncio.get_event_loop()

    # Creates frames only once to prevent filling the entire GPU
    print("CREATING CUDA OBJECT IN SERVER...")
    cuda_obj_generator = cloudpickle.loads(func)
    cuda_obj = cuda_obj_generator()
    msg = {"data": to_serialize(cuda_obj)}
    frames = loop.run_until_complete(
        to_frames(msg, serializers=("cuda", "dask", "pickle")))

    async def f(listener_port, frames):
        # coroutine shows up when the client asks
        # to connect

        if enable_rmm:
            set_rmm()

        # Use a global so the `write` callback function can read frames
        global _frames
        global _connected
        global _disconnected
        global _lock
        _connected = 0
        _disconnected = 0
        _lock = threading.Lock()
        _frames = frames

        async def write(ep):
            global _connected
            global _disconnected

            _lock.acquire()
            _connected += 1
            _lock.release()

            for i in range(TRANSFER_ITERATIONS):
                print("ITER: ", i)
                # Send meta data
                await send(ep, _frames)

            print("CONFIRM RECEIPT")
            await ep.close()

            _lock.acquire()
            _disconnected += 1
            _lock.release()
            # break

        lf = ucp.create_listener(write, port=listener_port)
        proc_conn.send("initialized")
        proc_conn.close()

        try:
            while _disconnected < num_workers * EP_ITERATIONS:
                await asyncio.sleep(0.1)
            print("Closing listener")
            lf.close()
        except ucp.UCXCloseError:
            pass

    loop.run_until_complete(f(port, frames))