【问题标题】:Flask/Bokeh/Tornado6.0.2: Embedded bokeh servers no longer work after Tornado updateFlask/Bokeh/Tornado6.0.2:Tornado 更新后嵌入式散景服务器不再工作
【发布时间】:2019-03-29 14:53:04
【问题描述】:

我在一个目录中有许多 Bokeh Server 文件,例如.. /dir/bokeh/,假设 bokeh 服务器名为 bokeh1.py、bokeh2.py、bokeh3.py 文件结构是这样的:

|--dir
    |---flask.py
    |---bokeh
          |--bokeh1.py
          |--bokeh2.py

我将它们全部部署在烧瓶上,如下所示:

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

argvs = {}
urls = []
for i in files:
    argvs[i] = None
    urls.append(i.split('\\')[-1].split('.')[0])
host = 'myhost.com'

apps = build_single_handler_applications(files, argvs)

bokeh_tornado = BokehTornado(apps, extra_websocket_origins=["myhost.com"])
bokeh_http = HTTPServer(bokeh_tornado)
sockets, port = bind_sockets("myhost.com", 0)
bokeh_http.add_sockets(sockets)

在更新到 Tornado 6.0.2 并部署 Flask 时,我收到了 Runtimerror There is no current event loop in thread Thread-1。在更深入的研究中,Tornado 默认使用asyncio 并施加一些限制。所以我在下面添加asyncio.set_event_loop(asyncio.new_event_loop())。

def bk_worker():
    asyncio.set_event_loop(asyncio.new_event_loop())####
    server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http)
    server.start()
    server.io_loop.start()
    gc.collect()

from threading import Thread

Thread(target=bk_worker).start()

但是,在通过烧瓶打开散景服务器 url 时,选择的散景服务器(其中任何一个)不会加载,只会返回一个空白页面。我该如何规避呢?

设置 asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy)) 会产生相同的结果。

edit:之前的代码适用于python 2/3,Tornado 4.5.3

【问题讨论】:

    标签: python-3.x flask tornado bokeh python-asyncio


    【解决方案1】:

    我认为这是一个已知的Bokeh issue。目前最好的方法是降级到 Tornado 4.5.3。

    pip install tornado==4.5.3
    

    【讨论】:

    • 非常感谢!我在这个问题上花了 4 个小时
    猜你喜欢
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    • 2017-11-04
    相关资源
    最近更新 更多