我对python的多重处理还是个新手,我对异步调用、yield和etc...the这类最基本的东西有一些概念。我看到了这段代码,其中multiprocessing.Process对tornado.ioloop.IOLoop.instance进行了包装
# Set up the tornado web app
app = make_app(predicted_model_queue)
app.listen(8080)
server_process = Process(target=tornado.ioloop.IOLoop.instance().start)
# Start up the server to expose the metrics.
server_process.start()它打算将tornado服务器作为server_process启动,但代码不起作用。我得到了错误,
OSError: [Errno 9] Bad file descriptor
我没有使用这两个库的经验,也不知道如何修复它。有谁能帮帮我吗?
发布于 2020-02-26 22:47:02
这是一个不同寻常的模式--如果你正在编写一个新的应用程序,我不建议你复制它。
如果你只是试图运行一个能做到这一点的应用程序(看起来像是来自here),问题是IOLoops不能安全地跨越进程边界(在某些平台上,它有时可以工作,但并不总是有效)。要重写此代码以在子进程中正确创建应用程序和IOLoop,您可以执行以下操作:
def run_server():
app = make_app(predicted_model_queue)
app.listen(8080)
tornado.ioloop.IOLoop.current().start()
server_process = Process(target=run_server)
server_process.start()这样,只有predicted_model_queue在两个进程之间共享。
https://stackoverflow.com/questions/60401509
复制相似问题