Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 对龙卷风的共同路线感到困惑_Python_Tornado_Coroutine - Fatal编程技术网

Python 对龙卷风的共同路线感到困惑

Python 对龙卷风的共同路线感到困惑,python,tornado,coroutine,Python,Tornado,Coroutine,我正试图找出龙卷风的py世代中流动的代码 future = TracebackFuture() if replace_callback and 'callback' in kwargs: callback = kwargs.pop('callback') IOLoop.current().add_future( future, lambda future: callback(future.result())) tr

我正试图找出龙卷风的py世代中流动的代码

    future = TracebackFuture()
    if replace_callback and 'callback' in kwargs:
        callback = kwargs.pop('callback')
        IOLoop.current().add_future(
            future, lambda future: callback(future.result()))

    try:
        result = func(*args, **kwargs)
    except (Return, StopIteration) as e:
        result = getattr(e, 'value', None)
    except Exception:
        future.set_exc_info(sys.exc_info())
        return future
    else:
        if isinstance(result, types.GeneratorType):
            try:
                orig_stack_contexts = stack_context._state.contexts
                yielded = next(result) # A (mark)
                if stack_context._state.contexts is not orig_stack_contexts:
                    yielded = TracebackFuture()
                    yielded.set_exception(
                        stack_context.StackContextInconsistentError(
                            'stack_context inconsistency (probably caused '
                            'by yield within a "with StackContext" block)'))
            except (StopIteration, Return) as e:
                future.set_result(getattr(e, 'value', None))
            except Exception:
                future.set_exc_info(sys.exc_info())
            else:
                Runner(result, future, yielded)
            try:
                return future
            finally:
                future = None
    future.set_result(result)  # B
    return future
我有两个功能

@coroutine
def foo():
     #do something
     bar = yield bar()
     #do something else

@coroutine
def bar():
     #do something
     return [1,2,3,4]
然后,调用
foo()
函数,代码运行到标记为A的点。函数
bar()
将被调用,因为
bar()
不是GeneratorType,它将像普通函数一样运行。接下来,设置future结果并返回future。在返回未来之前设置结果的这一点是最令人困惑的。在
bar()
返回未来之后,
foo()
获取此未来,但该未来在被
io\u循环处理之前设置了\u结果。添加\u future


任何帮助都将不胜感激,提前感谢。

我太愚蠢了,竟然忽略了代码:

if self.handle_yield(first_yielded): 
       self.run() 
如果未来完成,值将发送到相应的生成器