【发布时间】:2019-08-11 11:13:17
【问题描述】:
我正在尝试在烧瓶应用程序中运行多个 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
我想我在这里找到了解决方法Link To Question 我现在正在尝试使用提到的类似方法将地图服务器导入到flak,结果是这样的:
1.文件生成器(不知道为什么它不捡起来)
def build_single_handler_applications(paths, argvs=None):
applications = {}
argvs = {} or argvs
for path in paths:
application = build_single_handler_application(path, argvs.get(path, []))
route = application.handlers[0].url_path()
if not route:
if '/' in applications:
raise RuntimeError("Don't know the URL path to use for %s" % (path))
route = '/'
applications[route] = application
return applications
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.调用服务器并渲染模板的代码
@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
但是当我运行 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
我从 Bokeh 文档中找到并添加了 build_single_handler_application 函数只是因为这个错误,所以我不确定它是否是必需的或正确的。我想知道我缺少什么来完成这项工作,以防万一它是定位错误或缺少导入我在这里附加完整的烧瓶 webapp2.py 代码:
非常感谢您的帮助
【问题讨论】:
标签: python flask tornado bokeh