我主要使用Tornado来托管我的webapps,因此我可以告诉您,如果Tornado中的代码有任何部分被阻塞,那么整个服务器都将被阻塞。
现在到你的代码:
@tornado.gen.coroutine
def on_message(self, message):
process_results = yield self.process(message)
self.write_message(process_results)
@tornado.gen.coroutine
def process(self, message):
# a long process, this is the equivalent of time.sleep(2) which is blocking
yield tornado.gen.sleep(2)
return 'finished'
用
tornado
你必须
yield
从函数中获取返回值。
此外,如果函数正在生成,则必须使用
tornado.gen.coroutine
装饰工
这个
question
和你的相似。答案也很有用。