python – 无法在多个进程中运行:IOLoop实例已经初始化.在调用s
发布时间:2020-12-20 11:45:14 所属栏目:Python 来源:网络整理
导读:我正在尝试在Tornado中运行多个进程,我尝试了在这个线程上提出的建议: run multiple tornado processess 但错误并没有消失.这是服务器文件. server.py import osimport sysimport tornado#import pymongofrom tornado import ioloop,web,httpserver,websock
我正在尝试在Tornado中运行多个进程,我尝试了在这个线程上提出的建议:
run multiple tornado processess
但错误并没有消失.这是服务器文件. server.py import os import sys import tornado #import pymongo from tornado import ioloop,web,httpserver,websocket from tornado.options import options #Loading default setting files import settings #Motorengine - ODM for mongodb #from motorengine import connect app = tornado.web.Application(handlers=[ (r'/',MainHandler),(r'/ws',WSHandler),(r'/public/(.*)',tornado.web.StaticFileHandler,{'path': options.public_path})],template_path=os.path.join(os.path.dirname(__file__),"app/templates"),static_path= options.static_path,autoreload=True,#images=os.path.join(os.path.dirname(__file__),"images"),debug=False) if __name__ == '__main__': #read settings from commandline options.parse_command_line() server = tornado.httpserver.HTTPServer(app,max_buffer_size=1024*1024*201) server.bind(options.port) # autodetect cpu cores and fork one process per core server.start(0) #app.listen(options.port,xheaders=True) try: ioloop = tornado.ioloop.IOLoop.instance() #connect("attmlplatform",host="localhost",port=27017,io_loop=ioloop) print("Connected to database..") ioloop.start() print ('Server running on http://localhost:{}'.format(options.port)) except KeyboardInterrupt: tornado.ioloop.IOLoop.instance().stop() 我已根据预期可能触发实例注释掉’connect’导入,而我根本没有连接到数据库.这只是试图让服务器启动. 这是整个跟踪: File "server.py",line 52,in <module> server.start(0) File "/home/vagrant/anaconda3/envs/py34/lib/python3.4/site-packages/tornado/tcpserver.py",line 200,in start process.fork_processes(num_processes) File "/home/vagrant/anaconda3/envs/py34/lib/python3.4/site-packages/tornado/process.py",line 126,in fork_processes raise RuntimeError("Cannot run in multiple processes: IOLoop instance " RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start_processes() 任何建议非常感谢! 解决方法
autoreload与多进程模式不兼容.启用自动重载后,您必须只运行一个进程.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |