Windows 10 不同的会话使用单个bokeh服务器显示不同的流数据,如何解决?

Windows 10 不同的会话使用单个bokeh服务器显示不同的流数据,如何解决?,windows-10,bokeh,python-3.7,Windows 10,Bokeh,Python 3.7,我正在一个模拟的osilloscope上工作,服务器PC在那里收集数据,最终将在线发布流图。下面是一个可以完成这项工作的工作脚本。但是,当我打开多个浏览器时,流图显示不同的数据。(尽管它们使用相同的数据源)。示例“ohlc”似乎也有同样的问题。那么,正确的方法是什么呢?我正在考虑将数据写入文件,但这会带来一些问题,如文件I/o延迟和磁盘存储限制等。感谢您的帮助 当您与新客户机连接时,默认情况下,Bokeh会创建一个新会话。每个会话都有自己的文档,因此数据源最终不一样。谢谢,我也注意到了这一点

我正在一个模拟的osilloscope上工作,服务器PC在那里收集数据,最终将在线发布流图。下面是一个可以完成这项工作的工作脚本。但是,当我打开多个浏览器时,流图显示不同的数据。(尽管它们使用相同的数据源)。示例“ohlc”似乎也有同样的问题。那么,正确的方法是什么呢?我正在考虑将数据写入文件,但这会带来一些问题,如文件I/o延迟和磁盘存储限制等。感谢您的帮助


当您与新客户机连接时,默认情况下,Bokeh会创建一个新会话。每个会话都有自己的文档,因此数据源最终不一样。

谢谢,我也注意到了这一点。您有没有建议强制他们显示相同的流数据?您可以指定
bokeh会话id
query参数,类似于
http://localhost:5006/?bokeh-会话id=2
。但请注意,Bokeh目前并不打算用于此类用途,因此您可能会看到一些问题。在我这边,我看到第二个选项卡上的
DataRange1d
停止更新。
from bokeh.server.server import Server
from bokeh.models import ColumnDataSource, Label
from bokeh.plotting import figure
from bokeh.layouts import column
import numpy as np
import datetime as dt
from functools import partial
import time


# this will be replaced with the real data collector in the end
def f_emitter(p=0.1):
    v = np.random.rand()
    return (dt.datetime.now(), 0. if v>p else v)


def make_document(doc, functions, labels):
    def update():
        for index, func in enumerate(functions):
            data = func()
            sources[index].stream(new_data=dict(time=[data[0]], data=[data[1]]), rollover=1000)
            annotations[index].text = f'{data[1]: .3f}'

    sources = [ColumnDataSource(dict(time=[], data=[])) for _ in range(len(functions))]
    figs = []
    annotations = []
    for i in range(len(functions)):
        figs.append(figure(x_axis_type='datetime',
                           y_axis_label=labels[i], toolbar_location=None,
                           active_drag=None, active_scroll=None))
        figs[i].line(x='time', y='data', source=sources[i])
        annotations.append(Label(x=10, y=10, text='', text_font_size='40px', text_color='black',
                                 x_units='screen', y_units='screen', background_fill_color='white'))
        figs[i].add_layout(annotations[i])
        # print(figs[i].plot_height)

    doc.add_root(column([fig for fig in figs], sizing_mode='stretch_both'))
    doc.add_periodic_callback(callback=update, period_milliseconds=100)


if __name__ == '__main__':
    # list of functions and labels to feed into the scope
    functions = [f_emitter]
    labels = ['emitter']

    server = Server({'/': partial(make_document, functions=functions, labels=labels)})
    server.start()
    server.io_loop.add_callback(server.show, "/")
    try:
        server.io_loop.start()
    except KeyboardInterrupt:
        print('keyboard interruption')