本文介绍了相当于延迟的龙卷风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tornado 中是否有一个等效的命令用于延迟函数而不影响主进程休眠(因此即使在主线程正在处理新函数调用时回调也会执行)

Is there an equivalent command in tornado for delay function without affecting the main process to sleep (thus the callbacks would execute even when the main thread is dealying a new function call)

推荐答案

试试这个:

import time
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, asynchronous
from tornado import gen

class MyHandler(RequestHandler):
    @asynchronous
    @gen.engine
    def get(self):
        self.write("sleeping .... ")
        self.flush()
        # Do nothing for 5 sec
        yield gen.Task(IOLoop.instance().add_timeout, time.time() + 5)
        self.write("I'm awake!")
        self.finish()

取自此处.

这篇关于相当于延迟的龙卷风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:19
查看更多