本文整理汇总了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()
示例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