Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Don';不要等待异步函数完成_Python_Asynchronous_Tornado - Fatal编程技术网

Python Don';不要等待异步函数完成

Python Don';不要等待异步函数完成,python,asynchronous,tornado,Python,Asynchronous,Tornado,我有一个异步tornado服务器,它调用一个异步函数。但是,该函数只执行一些后台处理,我不想等待它完成。我该怎么做?以下是我的一个例子: @gen.coroutine def get(self): yield self.process('data') # I don't want to wait here self.write('page') @gen.coroutine def process(self, arg): d = yield gen

我有一个异步tornado服务器,它调用一个异步函数。但是,该函数只执行一些后台处理,我不想等待它完成。我该怎么做?以下是我的一个例子:

@gen.coroutine
def get(self):
    yield self.process('data') # I don't want to wait here
    self.write('page')

    @gen.coroutine
    def process(self, arg):
        d = yield gen.Task(self.otherFunc, arg)
        raise gen.Return(None)

只需在self.process('data')之前删除产量。它仍将运行,但get函数不会等待它完成。例如:

@gen.coroutine
def get(self):
    print 'a'
    yield self.process('data') # I don't want to wait here
    print 'b'
    self.write('page')

@gen.coroutine
def process(self, arg):
    print 'c'
    d = yield gen.Task(self.otherFunc, arg)
    print 'd'
    raise gen.Return(None)
将给出a、c、d、b,但:

@gen.coroutine
def get(self):
    print 'a'
    self.process('data') # I don't want to wait here
    print 'b'
    self.write('page')

@gen.coroutine
def process(self, arg):
    print 'c'
    d = yield gen.Task(self.otherFunc, arg)
    print 'd'
    raise gen.Return(None)

根据订单执行情况,可以给出a、c、b、d或a、b、c、d,但它不会再等待流程完成后才能到达“b”。

请注意,如果“流程”引发异常,则不会在任何地方记录它;在未来,你还没有屈服的情况将不会被报道。考虑在您调用Purror()的站点周围使用ExtExtStAcKEnter,以便记录它引发的任何错误:在TrnADO 4中,您应该使用IOOOP.SPAWNGUI回调来启动与调用方上下文分离的回调。IOLoop将记录将来包含的任何错误。