当前位置: 首页>>代码示例>>Python>>正文


Python Server.listen方法代码示例

本文整理汇总了Python中distributed.core.Server.listen方法的典型用法代码示例。如果您正苦于以下问题:Python Server.listen方法的具体用法?Python Server.listen怎么用?Python Server.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在distributed.core.Server的用法示例。


在下文中一共展示了Server.listen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_rpc_message_lifetime

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def check_rpc_message_lifetime(*listen_args):
    # Issue #956: rpc arguments and result shouldn't be kept alive longer
    # than necessary
    server = Server({'echo': echo_serialize})
    server.listen(*listen_args)

    # Sanity check
    obj = CountedObject()
    assert CountedObject.n_instances == 1
    del obj
    assert CountedObject.n_instances == 0

    with rpc(server.address) as remote:
        obj = CountedObject()
        res = yield remote.echo(x=to_serialize(obj))
        assert isinstance(res['result'], CountedObject)
        # Make sure resource cleanup code in coroutines runs
        yield gen.sleep(0.05)

        w1 = weakref.ref(obj)
        w2 = weakref.ref(res['result'])
        del obj, res

        assert w1() is None
        assert w2() is None
        # If additional instances were created, they were deleted as well
        assert CountedObject.n_instances == 0

    server.stop()
开发者ID:tomMoral,项目名称:distributed,代码行数:31,代码来源:test_core.py

示例2: f

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
    def f():
        server = Server({'ping': pingpong})
        with pytest.raises(ValueError):
            server.port
        server.listen(8881)
        assert server.port == 8881
        assert server.address == ('tcp://%s:8881' % get_ip())

        for addr in ('127.0.0.1:8881', 'tcp://127.0.0.1:8881', server.address):
            comm = yield connect(addr)

            n = yield comm.write({'op': 'ping'})
            assert isinstance(n, int)
            assert 4 <= n <= 1000

            response = yield comm.read()
            assert response == b'pong'

            yield comm.write({'op': 'ping', 'close': True})
            response = yield comm.read()
            assert response == b'pong'

            yield comm.close()

        server.stop()
开发者ID:tomMoral,项目名称:distributed,代码行数:27,代码来源:test_core.py

示例3: f

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
 def f():
     from distributed.core import Server
     from tornado.ioloop import IOLoop
     server = Server({'ping': pingpong})
     server.listen(8887)
     IOLoop.current().start()
     IOLoop.current().stop()
开发者ID:aterrel,项目名称:distributed,代码行数:9,代码来源:test_core.py

示例4: test_errors

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def test_errors():
    server = Server({'div': stream_div})
    server.listen(0)

    with rpc(('127.0.0.1', server.port)) as r:
        with pytest.raises(ZeroDivisionError):
            yield r.div(x=1, y=0)
开发者ID:tomMoral,项目名称:distributed,代码行数:9,代码来源:test_core.py

示例5: f

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
    def f():
        server = Server({})
        server.listen(8887)

        remote = rpc(ip='127.0.0.1', port=8887)
        a = yield remote.identity()
        b = yield remote.identity()
        assert a['type'] == 'Server'
        assert a['id'] == b['id']
开发者ID:lucashtnguyen,项目名称:distributed,代码行数:11,代码来源:test_core.py

示例6: test_errors

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def test_errors():
    server = Server({'div': stream_div})
    server.listen(0)

    r = rpc(ip='127.0.0.1', port=server.port)
    with pytest.raises(ZeroDivisionError):
        yield r.div(x=1, y=0)

    r.close_streams()
开发者ID:martindurant,项目名称:distributed,代码行数:11,代码来源:test_core.py

示例7: f

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
    def f():
        server = Server({'ping': pingpong})
        server.listen(8887)

        yield [g() for i in range(10)]

        server.stop()

        remote.close_streams()
        assert all(stream.closed() for stream in remote.streams)
开发者ID:martindurant,项目名称:distributed,代码行数:12,代码来源:test_core.py

示例8: test_deserialize_error

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def test_deserialize_error():
    server = Server({'throws': throws})
    server.listen(0)

    comm = yield connect(server.address, deserialize=False)
    with pytest.raises(Exception) as info:
        yield send_recv(comm, op='throws')

    assert type(info.value) == Exception
    for c in str(info.value):
        assert c.isalpha() or c in "(',!)"  # no crazy bytestrings
开发者ID:tomMoral,项目名称:distributed,代码行数:13,代码来源:test_core.py

示例9: check_identity

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def check_identity(listen_arg):
    server = Server({})
    server.listen(listen_arg)

    with rpc(server.address) as remote:
        a = yield remote.identity()
        b = yield remote.identity()
        assert a['type'] == 'Server'
        assert a['id'] == b['id']

    server.stop()
开发者ID:tomMoral,项目名称:distributed,代码行数:13,代码来源:test_core.py

示例10: test_counters

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def test_counters():
    server = Server({'div': stream_div})
    server.listen('tcp://')

    with rpc(server.address) as r:
        for i in range(2):
            yield r.identity()
        with pytest.raises(ZeroDivisionError):
            yield r.div(x=1, y=0)

        c = server.counters
        assert c['op'].components[0] == {'identity': 2, 'div': 1}
开发者ID:tomMoral,项目名称:distributed,代码行数:14,代码来源:test_core.py

示例11: f

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
    def f():
        server = Server({"ping": pingpong})
        server.listen(8887)

        remote = rpc(ip="127.0.0.1", port=8887)

        response = yield remote.ping()
        assert response == b"pong"

        response = yield remote.ping(close=True)
        assert response == b"pong"

        server.stop()
开发者ID:thrasibule,项目名称:distributed,代码行数:15,代码来源:test_core.py

示例12: f

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
    def f():
        server = Server({'ping': pingpong})
        server.listen(8887)

        with rpc(ip='127.0.0.1', port=8887) as remote:
            response = yield remote.ping()
            assert response == b'pong'

            response = yield remote.ping(close=True)
            assert response == b'pong'

        assert not remote.streams
        assert remote.status == 'closed'

        server.stop()
开发者ID:dask,项目名称:distributed,代码行数:17,代码来源:test_core.py

示例13: test_send_recv_args

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def test_send_recv_args():
    server = Server({'echo': echo})
    server.listen(0)

    comm = yield connect(server.address)
    result = yield send_recv(comm, op='echo', x=b'1')
    assert result == b'1'
    assert not comm.closed()
    result = yield send_recv(comm, op='echo', x=b'2', reply=False)
    assert result is None
    assert not comm.closed()
    result = yield send_recv(comm, op='echo', x=b'3', close=True)
    assert result == b'3'
    assert comm.closed()

    server.stop()
开发者ID:tomMoral,项目名称:distributed,代码行数:18,代码来源:test_core.py

示例14: check_rpc_with_many_connections

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def check_rpc_with_many_connections(listen_arg):
    @gen.coroutine
    def g():
        for i in range(10):
            yield remote.ping()

    server = Server({'ping': pingpong})
    server.listen(listen_arg)

    remote = rpc(server.address)
    yield [g() for i in range(10)]

    server.stop()

    remote.close_comms()
    assert all(comm.closed() for comm in remote.comms)
开发者ID:tomMoral,项目名称:distributed,代码行数:18,代码来源:test_core.py

示例15: check_large_packets

# 需要导入模块: from distributed.core import Server [as 别名]
# 或者: from distributed.core.Server import listen [as 别名]
def check_large_packets(listen_arg):
    """ tornado has a 100MB cap by default """
    server = Server({'echo': echo})
    server.listen(listen_arg)

    data = b'0' * int(200e6)  # slightly more than 100MB
    conn = rpc(server.address)
    result = yield conn.echo(x=data)
    assert result == data

    d = {'x': data}
    result = yield conn.echo(x=d)
    assert result == d

    conn.close_comms()
    server.stop()
开发者ID:tomMoral,项目名称:distributed,代码行数:18,代码来源:test_core.py


注:本文中的distributed.core.Server.listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。