pop() — flask Function Reference
Architecture documentation for the pop() function in ctx.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD f3e4082a_363a_71e3_d71c_811f4abdcc27["pop()"] 275727eb_1ded_d769_967a_a19802db308a["AppContext"] f3e4082a_363a_71e3_d71c_811f4abdcc27 -->|defined in| 275727eb_1ded_d769_967a_a19802db308a 401293cb_88b7_fe8d_ebb9_718382581673["pop()"] 401293cb_88b7_fe8d_ebb9_718382581673 -->|calls| f3e4082a_363a_71e3_d71c_811f4abdcc27 29c01b52_dfc0_3a3d_4742_ea3f91051ed4["__exit__()"] 29c01b52_dfc0_3a3d_4742_ea3f91051ed4 -->|calls| f3e4082a_363a_71e3_d71c_811f4abdcc27 401293cb_88b7_fe8d_ebb9_718382581673["pop()"] f3e4082a_363a_71e3_d71c_811f4abdcc27 -->|calls| 401293cb_88b7_fe8d_ebb9_718382581673 93a9b153_9546_2c3e_8d99_ef02db43e9b7["get()"] f3e4082a_363a_71e3_d71c_811f4abdcc27 -->|calls| 93a9b153_9546_2c3e_8d99_ef02db43e9b7 588a6d29_7dfb_6988_df9d_e5db19f923e8["do_teardown_request()"] f3e4082a_363a_71e3_d71c_811f4abdcc27 -->|calls| 588a6d29_7dfb_6988_df9d_e5db19f923e8 4db439cf_e411_a943_383f_a55c855832ec["do_teardown_appcontext()"] f3e4082a_363a_71e3_d71c_811f4abdcc27 -->|calls| 4db439cf_e411_a943_383f_a55c855832ec style f3e4082a_363a_71e3_d71c_811f4abdcc27 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/ctx.py lines 432–480
def pop(self, exc: BaseException | None = None) -> None:
"""Pop this context so that it is no longer the active context. Then
call teardown functions and signals.
Typically, this is not used directly. Instead, use a ``with`` block
to manage the context.
This context must currently be the active context, otherwise a
:exc:`RuntimeError` is raised. In some situations, such as streaming or
testing, the context may have been pushed multiple times. It will only
trigger cleanup once it has been popped as many times as it was pushed.
Until then, it will remain the active context.
:param exc: An unhandled exception that was raised while the context was
active. Passed to teardown functions.
.. versionchanged:: 0.9
Added the ``exc`` argument.
"""
if self._cv_token is None:
raise RuntimeError(f"Cannot pop this context ({self!r}), it is not pushed.")
ctx = _cv_app.get(None)
if ctx is None or self._cv_token is None:
raise RuntimeError(
f"Cannot pop this context ({self!r}), there is no active context."
)
if ctx is not self:
raise RuntimeError(
f"Cannot pop this context ({self!r}), it is not the active"
f" context ({ctx!r})."
)
self._push_count -= 1
if self._push_count > 0:
return
try:
if self._request is not None:
self.app.do_teardown_request(self, exc)
self._request.close()
finally:
self.app.do_teardown_appcontext(self, exc)
_cv_app.reset(self._cv_token)
self._cv_token = None
appcontext_popped.send(self.app, _async_wrapper=self.app.ensure_sync)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does pop() do?
pop() is a function in the flask codebase, defined in src/flask/ctx.py.
Where is pop() defined?
pop() is defined in src/flask/ctx.py at line 432.
What does pop() call?
pop() calls 4 function(s): do_teardown_appcontext, do_teardown_request, get, pop.
What calls pop()?
pop() is called by 2 function(s): __exit__, pop.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free