【问题标题】:Simple function and tornado gen.engine简单函数和tornado gen.engine
【发布时间】:2013-08-29 10:06:06
【问题描述】:

我正在使用 Python + Tornado 制作一个 Web 应用程序。例如写了一个简单的处理程序:

class AdminHandler(BaseHandler):

@tornado.web.authenticated
@tornado.web.asynchronous
@gen.engine
def get(self):
    response = yield gen.Task(self.acync_func_test, 'my')
    print response
    self.render('admin/index.html')


def acync_func_test(self, argument, callback):
    for i in xrange(1,59999000):
        i**2+2-12
    callback(argument)

但是函数不是异步执行的。其他客户端正在等待,直到第一次执行查询。如何实现非阻塞执行?

更新:

在你的 async_func_test() 函数中添加了装饰器“@gen.engine”,但仍然被阻塞((

【问题讨论】:

    标签: python tornado


    【解决方案1】:

    将装饰器“@gen.engine”添加到您的 async_func_test() 函数中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 2019-04-15
      • 2015-11-29
      • 2012-10-18
      相关资源
      最近更新 更多