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


Python client.ClientSession类代码示例

本文整理汇总了Python中bokeh.client.ClientSession的典型用法代码示例。如果您正苦于以下问题:Python ClientSession类的具体用法?Python ClientSession怎么用?Python ClientSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_session_show_adds_obj_to_curdoc_if_necessary

def test_session_show_adds_obj_to_curdoc_if_necessary(m):
    session = ClientSession()
    session._document = Document()
    p = Plot()
    assert session.document.roots == []
    session.show(p)
    assert session.document.roots == [p]
开发者ID:280185386,项目名称:bokeh,代码行数:7,代码来源:test_client_server.py

示例2: test_minimal_connect_and_disconnect

 def test_minimal_connect_and_disconnect(self):
     application = Application()
     with ManagedServerLoop(application) as server:
         # we don't have to start the server because it
         # uses the same main loop as the client, so
         # if we start either one it starts both
         session = ClientSession(io_loop = server.io_loop,
                                 url = ws_url(server))
         session.connect()
         assert session.connected
开发者ID:SandraKilpatrick,项目名称:bokeh,代码行数:10,代码来源:test_client_server.py

示例3: test_disconnect_on_error

 def test_disconnect_on_error(self):
     application = Application()
     with ManagedServerLoop(application) as server:
         session = ClientSession(url=server.ws_url, io_loop = server.io_loop)
         session.connect()
         assert session.connected
         # send a bogus message using private fields
         session._connection._socket.write_message(b"xx", binary=True)
         # connection should now close on the server side
         # and the client loop should end
         session.loop_until_closed()
         assert not session.connected
开发者ID:rbtr,项目名称:bokeh,代码行数:12,代码来源:test_client_server.py

示例4: test_session_periodic_callback

    def test_session_periodic_callback(self):
        application = Application()
        with ManagedServerLoop(application) as server:
            doc = document.Document()

            client_session = ClientSession(session_id='test_client_session_callback',
                                          url=ws_url(server),
                                          io_loop=server.io_loop)
            server_session = ServerSession(session_id='test_server_session_callback',
                                           document=doc, io_loop=server.io_loop)
            client_session._attach_document(doc)

            assert len(server_session._callbacks) == 0
            assert len(client_session._callbacks) == 0

            def cb(): pass
            callback = doc.add_periodic_callback(cb, 1, 'abc')
            server_session2 = ServerSession('test_server_session_callback',
                                            doc, server.io_loop)

            assert server_session2._callbacks
            assert len(server_session._callbacks) == 1
            assert len(client_session._callbacks) == 1

            started_callbacks = []
            for ss in [server_session, server_session2]:
                iocb = ss._callbacks[callback.id]
                assert iocb._period == 1
                assert iocb._loop == server.io_loop
                assert iocb._handle is not None
                started_callbacks.append(iocb)

            for ss in [client_session]:
                iocb = ss._callbacks[callback.id]
                assert isinstance(iocb, PeriodicCallback)
                assert iocb.callback_time == 1
                assert iocb.io_loop == server.io_loop
                assert iocb.is_running()
                started_callbacks.append(iocb)

            callback = doc.remove_periodic_callback(cb)
            assert len(server_session._callbacks) == 0
            assert len(client_session._callbacks) == 0
            assert len(server_session._callbacks) == 0

            for iocb in started_callbacks:
                if hasattr(iocb, '_handle'):
                    assert iocb._handle is None
                else:
                    assert not iocb.is_running()
开发者ID:SandraKilpatrick,项目名称:bokeh,代码行数:50,代码来源:test_client_server.py

示例5: test_session_timeout_callback

    def test_session_timeout_callback(self):
        application = Application()
        with ManagedServerLoop(application) as server:
            doc = document.Document()

            client_session = ClientSession(session_id='test_client_session_callback',
                                          url=ws_url(server),
                                          io_loop=server.io_loop)
            server_session = ServerSession(session_id='test_server_session_callback',
                                           document=doc, io_loop=server.io_loop)
            client_session._attach_document(doc)

            assert len(server_session._callbacks) == 0
            assert len(client_session._callbacks) == 0

            def cb(): pass

            x = server.io_loop.time()
            callback = doc.add_timeout_callback(cb, 10, 'abc')
            server_session2 = ServerSession('test_server_session_callback',
                                            doc, server.io_loop)

            assert server_session2._callbacks
            assert len(server_session._callbacks) == 1
            assert len(client_session._callbacks) == 1

            started_callbacks = []
            for ss in [server_session, client_session, server_session2]:
                iocb = ss._callbacks[callback.id]
                assert isinstance(iocb, _Timeout)

                # check that the callback deadline is 10
                # milliseconds later from when we called
                # add_timeout_callback (using int to avoid ms
                # differences between the x definition and the
                # call)
                assert abs(int(iocb.deadline) - int(x + 10/1000.0)) < 1e6
                started_callbacks.append(iocb)

            callback = doc.remove_timeout_callback(cb)
            assert len(server_session._callbacks) == 0
            assert len(client_session._callbacks) == 0
            assert len(server_session._callbacks) == 0
开发者ID:SandraKilpatrick,项目名称:bokeh,代码行数:43,代码来源:test_client_server.py

示例6: test_request_server_info

    def test_request_server_info(self):
        application = Application()
        with ManagedServerLoop(application) as server:
            session = ClientSession(url=server.ws_url, io_loop=server.io_loop)
            session.connect()
            assert session.connected
            assert session.document is None

            info = session.request_server_info()

            from bokeh import __version__

            assert info['version_info']['bokeh'] == __version__
            assert info['version_info']['server'] == __version__

            session.close()
            session.loop_until_closed()
            assert not session.connected
开发者ID:rbtr,项目名称:bokeh,代码行数:18,代码来源:test_client_server.py

示例7: test_request_server_info

    def test_request_server_info(self):
        application = Application()
        with ManagedServerLoop(application) as server:
            session = ClientSession(session_id='test_request_server_info',
                                    websocket_url=ws_url(server),
                                    io_loop=server.io_loop)
            session.connect()
            assert session.connected
            assert session.document is None

            info = session.request_server_info()

            from bokeh import __version__

            assert info['version_info']['bokeh'] == __version__
            assert info['version_info']['server'] == __version__

            session.close()
            session.loop_until_closed(suppress_warning=True)
            assert not session.connected
开发者ID:digitalsatori,项目名称:Bokeh,代码行数:20,代码来源:test_client_server.py

示例8: test_connect_with_prefix

    def test_connect_with_prefix(self):
        application = Application()
        with ManagedServerLoop(application, prefix="foo") as server:
            # we don't have to start the server because it
            # uses the same main loop as the client, so
            # if we start either one it starts both
            session = ClientSession(io_loop = server.io_loop,
                                    websocket_url = ws_url(server, "/foo"))
            session.connect()
            assert session.connected
            session.close()
            session.loop_until_closed()

            session = ClientSession(io_loop = server.io_loop,
                                    websocket_url = ws_url(server))
            session.connect()
            assert not session.connected
            session.close()
            session.loop_until_closed()
开发者ID:280185386,项目名称:bokeh,代码行数:19,代码来源:test_client_server.py

示例9: test_ping

    def test_ping(self):
        application = Application()
        with ManagedServerLoop(application, keep_alive_milliseconds=0) as server:
            session = ClientSession(session_id='test_ping',
                                    websocket_url=ws_url(server),
                                    io_loop=server.io_loop)
            session.connect()
            assert session.connected
            assert session.document is None

            connection = next(iter(server._tornado._clients))
            expected_pong = connection._ping_count
            server._tornado.keep_alive() # send ping
            session.force_roundtrip()

            self.assertEqual(expected_pong, connection._socket.latest_pong)

            # check that each ping increments by 1
            server._tornado.keep_alive()
            session.force_roundtrip()

            self.assertEqual(expected_pong + 1, connection._socket.latest_pong)

            session.close()
            session.loop_until_closed()
            assert not session.connected
开发者ID:280185386,项目名称:bokeh,代码行数:26,代码来源:test_client_server.py

示例10: test_host_whitelist_success

    def test_host_whitelist_success(self):
        application = Application()

        # succeed no host value with defaults
        with ManagedServerLoop(application, host=None) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert session.connected
            session.close()
            session.loop_until_closed()

        # succeed no host value with port
        with ManagedServerLoop(application, port=8080, host=None) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert session.connected
            session.close()
            session.loop_until_closed()

        # succeed matching host value
        with ManagedServerLoop(application, port=8080, host=["localhost:8080"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert session.connected
            session.close()
            session.loop_until_closed()

        # succeed matching host value one of multiple
        with ManagedServerLoop(application, port=8080, host=["bad_host", "localhost:8080"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert session.connected
            session.close()
            session.loop_until_closed()
开发者ID:SandraKilpatrick,项目名称:bokeh,代码行数:34,代码来源:test_client_server.py

示例11: test_host_whitelist_failure

    def test_host_whitelist_failure(self):
        application = Application()

        # failure bad host
        with ManagedServerLoop(application, host=["bad_host"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert not session.connected
            session.close()
            session.loop_until_closed()

        with ManagedServerLoop(application, host=["bad_host:5006"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert not session.connected
            session.close()
            session.loop_until_closed()

        # failure good host, bad port
        with ManagedServerLoop(application, host=["localhost:80"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert not session.connected
            session.close()
            session.loop_until_closed()

        # failure good host, bad default port
        with ManagedServerLoop(application, host=["localhost"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert not session.connected
            session.close()
            session.loop_until_closed()

        # failure with custom port
        with ManagedServerLoop(application, port=8080, host=["localhost:8081"]) as server:
            session = ClientSession(url=ws_url(server), io_loop = server.io_loop)
            session.connect()
            assert not session.connected
            session.close()
            session.loop_until_closed()
开发者ID:SandraKilpatrick,项目名称:bokeh,代码行数:41,代码来源:test_client_server.py


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