【发布时间】:2017-03-13 15:37:17
【问题描述】:
我一直在尝试使用以下代码在多进程模式下使用 aiomysql 运行 tornado
@asyncio.coroutine
def get_mysql_connection(loop):
return (yield from aiomysql.create_pool(host=host,port=3306,user=user, password=pass, db=db, loop=loop))
if __name__ == "__main__":
tornado.platform.asyncio.AsyncIOMainLoop().install()
ioloop = asyncio.get_event_loop()
mysql = ioloop.run_until_complete(get_mysql_connection(ioloop))
options.parse_config_file("app.conf")
app = make_app(mysql)
print('listening on %s:%s...' %(options.host, options.port))
server = tornado.httpserver.HTTPServer(app)
server.listen(options.port)
server.start(0) #this is my problem
ioloop.run_forever()
但我不断收到以下错误
RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start_processes()
除了ioloop.start(0) 行之外,一切都运行良好,是否可以让aiomysql 和tornado 这两个库在多进程模式下正常工作?如果没有,我的其他选择是什么
Tornado 版本 4.4.2
python 版本 3.6.0
aiomysql 0.0.9版
【问题讨论】:
标签: python-3.x tornado python-asyncio