高手请进,请教一下tornado框架的一个问题。

ymy1248227142 2015-12-02 11:20:07
代码如下:

#/test
class Test(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.coroutine
def get(self):
res = yield self.inner()
self.write(res)

@tornado.gen.coroutine
def inner(self):
import time
time.sleep(15)
raise tornado.gen.Return('hello')

#/test_1
class Test1(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.coroutine
def get(self):
res = yield self.inner()
self.write(res)

@tornado.gen.coroutine
def inner(self):
raise tornado.gen.Return('hello test1')



上面是我的handler代码,当我访问/test然后访问/test_1的时候我发现并没有异步呢,要等到15秒过后/test
返回了过后,/test_1才会返回!异步不是应该不会挂起吗?/test还没返回的时候 /test_1应该可以相应才对呀?
...全文
10977 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35234790 2016-06-07
  • 打赏
  • 举报
回复
好像不能用time.sleep函数,因为这个函数本身就会阻塞线程

2,763

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ruby/Rails
社区管理员
  • Ruby/Rails社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧