社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Therenca

Therenca 最近创建的主题
Therenca 最近回复了
5 年前
回复了 Therenca 创建的主题 » python tornado websocket服务器瓶颈

我主要使用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 和你的相似。答案也很有用。