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


Python ClientSession._attach_document方法代码示例

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


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

示例1: test_session_periodic_callback

# 需要导入模块: from bokeh.client import ClientSession [as 别名]
# 或者: from bokeh.client.ClientSession import _attach_document [as 别名]
    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,代码行数:52,代码来源:test_client_server.py

示例2: test_session_timeout_callback

# 需要导入模块: from bokeh.client import ClientSession [as 别名]
# 或者: from bokeh.client.ClientSession import _attach_document [as 别名]
    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,代码行数:45,代码来源:test_client_server.py


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