Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将多个Bokeh服务器集成到Flask_Python_Flask_Tornado_Bokeh - Fatal编程技术网

Python 将多个Bokeh服务器集成到Flask

Python 将多个Bokeh服务器集成到Flask,python,flask,tornado,bokeh,Python,Flask,Tornado,Bokeh,我正在尝试在flask应用程序中运行多个Bokeh服务器,使用如下方法,绘图可以自己正确运行: def getTimePlot(): script = server_document('http://localhost:5006/timeseries') return render_template("displaytimeseries.html", script=script, template="Flask") def startPlotserver(): s

我正在尝试在flask应用程序中运行多个Bokeh服务器,使用如下方法,绘图可以自己正确运行:

  def getTimePlot():
   script = server_document('http://localhost:5006/timeseries')
   return render_template("displaytimeseries.html", script=script, template="Flask")    
def startPlotserver():
    server.start()
    server = Server({'/timeseries': modifyTimeSeries}, io_loop=IOLoop(), allow_websocket_origin=["localhost:8000"])
    server.io_loop.start() 
if __name__ == '__main__':
    print('Opening single process Flask app with embedded Bokeh application on http://localhost:8000/')
    print()
    print('Multiple connections may block the Bokeh app in this configuration!')
    print('See "flask_gunicorn_embed.py" for one way to run multi-process')
    app.run(port=5000, debug=True)
但是,当我尝试使用这种方法将两台服务器嵌入到一起时,我会遇到以下问题:

文件结构:

|--app4
    |---webapp2.py
    |---bokeh
          |--timeseries.py
          |--map.py
    @app.route('/crimeMap', methods=['GET'])
def getCrimeMap():
    bokeh_script = server_document("http://localhost:5006:%d/map" % port) 
    return render_template("displaymap1.html", bokeh_script=bokeh_script)
我想我在这里找到了解决办法 我正在尝试使用前面提到的类似方法将地图服务器导入flak,结果如下:

1。文件生成器(不确定它为什么不拾取它)

2。查找文件和创建连接的代码

    files=[]
for file in os.listdir("bokeh"):
    if file.endswith('.py'):
        file="map"+file
        files.append(file)

argvs = {}
urls = []
for i in files:
    argvs[i] = None
    urls.append(i.split('\\')[-1].split('.')[0])
host = 'http://localhost:5006/map'

apps = build_single_handler_applications(files, argvs)

bokeh_tornado = BokehTornado(apps, extra_websocket_origins=["localhost:8000"])
bokeh_http = HTTPServer(bokeh_tornado)
sockets, port = bind_sockets("localhost:8000", 5000)
bokeh_http.add_sockets(sockets)
3。调用服务器并呈现模板的代码

|--app4
    |---webapp2.py
    |---bokeh
          |--timeseries.py
          |--map.py
    @app.route('/crimeMap', methods=['GET'])
def getCrimeMap():
    bokeh_script = server_document("http://localhost:5006:%d/map" % port) 
    return render_template("displaymap1.html", bokeh_script=bokeh_script)
我在一个命令中运行两个Bokeh服务器,如下所示

bokeh serve timeseries.py map.py --allow-websocket-origin=127.0.0.1:5000
  bokeh serve timeseries.py --port 5100 --allow-websocket-origin=localhost:5567

bokeh serve map.py --port 5200 --allow-websocket-origin=localhost:5567
但是,当我运行webapp2.py时,会出现以下错误:

    (env1) C:\Users\Dell1525\Desktop\flaskapp\env1\app4>webapp2.py
Traceback (most recent call last):
  File "C:\Users\Dell1525\Desktop\flaskapp\env1\app4\webapp2.py", line 113, in <module>
    apps = build_single_handler_applications(files, argvs)
  File "C:\Users\Dell1525\Desktop\flaskapp\env1\app4\webapp2.py", line 29, in build_single_handler_applications
    application = build_single_handler_application(path, argvs.get(path, []))
NameError: name 'build_single_handler_application' is not defined
(env1)C:\Users\Dell1525\Desktop\flaskapp\env1\app4>webapp2.py
回溯(最近一次呼叫最后一次):
文件“C:\Users\Dell1525\Desktop\flaskapp\env1\app4\webapp2.py”,第113行,在
应用程序=生成\u单个\u处理程序\u应用程序(文件、argv)
文件“C:\Users\Dell1525\Desktop\flaskapp\env1\app4\webapp2.py”,第29行,内置单处理器应用程序
application=build\u single\u handler\u应用程序(路径,argvs.get(路径,[]))
NameError:未定义名称“生成\u单个\u处理程序\u应用程序”
我从Bokeh文档中找到并添加了build_single_handler_应用程序函数,只是因为这个错误,所以我不确定它是必需的还是正确的。我想知道我在这里附加完整的flask webapp2.py代码时,为了防止定位错误或缺少导入,我遗漏了什么来实现此功能:


非常感谢您的帮助

我通过稍微调整这个示例找到了一个更简单的解决方案:请注意,这要求您拥有tornado 4.4.1,因为它不适用于较新的版本

诀窍是单独运行所有服务器,并在具有相同套接字访问的不同端口上运行,如下所示

bokeh serve timeseries.py map.py --allow-websocket-origin=127.0.0.1:5000
  bokeh serve timeseries.py --port 5100 --allow-websocket-origin=localhost:5567

bokeh serve map.py --port 5200 --allow-websocket-origin=localhost:5567

对于那些可能觉得这很有用的人,我已经包括了完整的工作解决方案,通过稍微调整这个示例,我找到了一个更简单的解决方案:注意,这要求您使用tornado 4.4.1,因为它不适用于较新的版本

诀窍是单独运行所有服务器,并在具有相同套接字访问的不同端口上运行,如下所示

bokeh serve timeseries.py map.py --allow-websocket-origin=127.0.0.1:5000
  bokeh serve timeseries.py --port 5100 --allow-websocket-origin=localhost:5567

bokeh serve map.py --port 5200 --allow-websocket-origin=localhost:5567
对于那些可能认为这很有用的人,我已经包括了完整的工作解决方案

“工作代码链接”已断开。你能在这里分享代码吗?“工作代码链接”断开了。你能在这里分享代码吗?