Python Flask如何处理现有应用程序上下文的请求?

Python Flask如何处理现有应用程序上下文的请求?,python,flask,Python,Flask,根据(矿山)的重点: 根据需要创建和销毁应用程序上下文。信息技术 永远不要在线程之间移动,并且它不会在线程之间共享 请求… 不过,我觉得这本书的相关部分有点奇怪: # Before we push the request context we have to ensure that there # is an application context. app_ctx = _app_ctx_stack.top if app_ctx is None or app_ctx.app != self.ap

根据(矿山)的重点:

根据需要创建和销毁应用程序上下文。信息技术 永远不要在线程之间移动,并且它不会在线程之间共享 请求…

不过,我觉得这本书的相关部分有点奇怪:

# Before we push the request context we have to ensure that there
# is an application context.
app_ctx = _app_ctx_stack.top
if app_ctx is None or app_ctx.app != self.app:
    app_ctx = self.app.app_context()
    app_ctx.push()
    self._implicit_app_ctx_stack.append(app_ctx)
else:
    self._implicit_app_ctx_stack.append(None)
如您所见,当
app_ctx为None或app_ctx.app!=self.app
False
,除了
None
被附加到
self.\u implicit\u app\u ctx\u stack
,没有任何操作,因此我怀疑现有的应用程序上下文被重复使用,即在请求之间共享

更复杂的是,还显示了在请求之间保留应用程序上下文(因为在第一个请求之后,
g.foo
仍然包含
xzy

也就是说,该文档与源代码和实验不一致。那么,当存在现有的应用程序上下文时,Flask究竟如何处理即将到来的请求呢