我的python版本是3.4,tornado版本是4.3。 我有两个服务器,它们必须在运行时共享一些数据,我的代码是这样的
from tornado.web import gen, asynchronous, RequestHandler, Application
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
class HelloHandler(RequestHandler):
@asynchronous
@gen.engine
def get(self):
self.write('hello')
self.finish()
class MainHandler(RequestHandler):
@asynchronous
@gen.engine
def get(self):
self.write('main')
self.finish()
helloApp = Application([
(r'/hello', HelloHandler),
])
mainApp = Application([
(r'/main', MainHandler),
])
if __name__ == "__main__":
hello_server = HTTPServer(helloApp)
hello_server.bind(8881)
hello_server.start()
# hello_server.start(0)
main_server = HTTPServer(mainApp)
main_server.bind(8882)
main_server.start()
# main_server.start(0)
IOLoop.current().start()
它可以工作,但是当我试图通过使用服务器启动(0),我收到一个错误:'OSError:[Errno 98]地址已在使用中,我已经使用了不同的端口(8881,8882)。这是怎么发生的? 怎么解决呢?在
start(n)
仅适用于单个服务器。要使用多个,必须分别使用bind_sockets
、fork_processes
和{相关问题 更多 >
编程相关推荐