Method: flask.ctx.RequestContext.pop
Calls: 534, Exceptions: 1, Paths: 5Back
Path 1: 498 calls (0.93)
None (462) ZeroDivisionError (12) TypeError (5) KeyError (4) BadRequestKeyError (2) Exception (2) TestGenericHandlers.Custom (2) ValueError (1) Keyboa...
1def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
2 """Pops the request context and unbinds it by doing that. This will
3 also trigger the execution of functions registered by the
4 :meth:`~flask.Flask.teardown_request` decorator.
5
6 .. versionchanged:: 0.9
7 Added the `exc` argument.
8 """
9 clear_request = len(self._cv_tokens) == 1
10
11 try:
12 if clear_request:
13 if exc is _sentinel:
14 exc = sys.exc_info()[1]
15 self.app.do_teardown_request(exc)
16
17 request_close = getattr(self.request, "close", None)
18 if request_close is not None:
19 request_close()
20 finally:
21 ctx = _cv_request.get()
22 token, app_ctx = self._cv_tokens.pop()
23 _cv_request.reset(token)
24
25 # get rid of circular dependencies at the end of the request
26 # so that we don't require the GC to be active.
27 if clear_request:
28 ctx.request.environ["werkzeug.request"] = None
29
30 if app_ctx is not None:
31 app_ctx.pop(exc)
32
33 if ctx is not self:
34 raise AssertionError(
35 f"Popped wrong request context. ({ctx!r} instead of {self!r})"
36 )
Path 2: 24 calls (0.04)
None (22) ValueError (1) GeneratorExit (1)
1def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
2 """Pops the request context and unbinds it by doing that. This will
3 also trigger the execution of functions registered by the
4 :meth:`~flask.Flask.teardown_request` decorator.
5
6 .. versionchanged:: 0.9
7 Added the `exc` argument.
8 """
9 clear_request = len(self._cv_tokens) == 1
10
11 try:
12 if clear_request:
13 if exc is _sentinel:
14 exc = sys.exc_info()[1]
15 self.app.do_teardown_request(exc)
16
17 request_close = getattr(self.request, "close", None)
18 if request_close is not None:
19 request_close()
20 finally:
21 ctx = _cv_request.get()
22 token, app_ctx = self._cv_tokens.pop()
23 _cv_request.reset(token)
24
25 # get rid of circular dependencies at the end of the request
26 # so that we don't require the GC to be active.
27 if clear_request:
28 ctx.request.environ["werkzeug.request"] = None
29
30 if app_ctx is not None:
31 app_ctx.pop(exc)
32
33 if ctx is not self:
34 raise AssertionError(
35 f"Popped wrong request context. ({ctx!r} instead of {self!r})"
36 )
Path 3: 8 calls (0.01)
None (8)
1def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
2 """Pops the request context and unbinds it by doing that. This will
3 also trigger the execution of functions registered by the
4 :meth:`~flask.Flask.teardown_request` decorator.
5
6 .. versionchanged:: 0.9
7 Added the `exc` argument.
8 """
9 clear_request = len(self._cv_tokens) == 1
10
11 try:
12 if clear_request:
13 if exc is _sentinel:
14 exc = sys.exc_info()[1]
15 self.app.do_teardown_request(exc)
16
17 request_close = getattr(self.request, "close", None)
18 if request_close is not None:
19 request_close()
20 finally:
21 ctx = _cv_request.get()
22 token, app_ctx = self._cv_tokens.pop()
23 _cv_request.reset(token)
24
25 # get rid of circular dependencies at the end of the request
26 # so that we don't require the GC to be active.
27 if clear_request:
28 ctx.request.environ["werkzeug.request"] = None
29
30 if app_ctx is not None:
31 app_ctx.pop(exc)
32
33 if ctx is not self:
34 raise AssertionError(
35 f"Popped wrong request context. ({ctx!r} instead of {self!r})"
36 )
Path 4: 3 calls (0.01)
object (3)
1def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
2 """Pops the request context and unbinds it by doing that. This will
3 also trigger the execution of functions registered by the
4 :meth:`~flask.Flask.teardown_request` decorator.
5
6 .. versionchanged:: 0.9
7 Added the `exc` argument.
8 """
9 clear_request = len(self._cv_tokens) == 1
10
11 try:
12 if clear_request:
13 if exc is _sentinel:
14 exc = sys.exc_info()[1]
15 self.app.do_teardown_request(exc)
16
17 request_close = getattr(self.request, "close", None)
18 if request_close is not None:
19 request_close()
20 finally:
21 ctx = _cv_request.get()
22 token, app_ctx = self._cv_tokens.pop()
23 _cv_request.reset(token)
24
25 # get rid of circular dependencies at the end of the request
26 # so that we don't require the GC to be active.
27 if clear_request:
28 ctx.request.environ["werkzeug.request"] = None
29
30 if app_ctx is not None:
31 app_ctx.pop(exc)
32
33 if ctx is not self:
34 raise AssertionError(
35 f"Popped wrong request context. ({ctx!r} instead of {self!r})"
36 )
Path 5: 1 calls (0.0)
None (1)
ZeroDivisionError (1)
1def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
2 """Pops the request context and unbinds it by doing that. This will
3 also trigger the execution of functions registered by the
4 :meth:`~flask.Flask.teardown_request` decorator.
5
6 .. versionchanged:: 0.9
7 Added the `exc` argument.
8 """
9 clear_request = len(self._cv_tokens) == 1
10
11 try:
12 if clear_request:
13 if exc is _sentinel:
14 exc = sys.exc_info()[1]
15 self.app.do_teardown_request(exc)
16
17 request_close = getattr(self.request, "close", None)
18 if request_close is not None:
19 request_close()
20 finally:
21 ctx = _cv_request.get()
22 token, app_ctx = self._cv_tokens.pop()
23 _cv_request.reset(token)
24
25 # get rid of circular dependencies at the end of the request
26 # so that we don't require the GC to be active.
27 if clear_request:
28 ctx.request.environ["werkzeug.request"] = None
29
30 if app_ctx is not None:
31 app_ctx.pop(exc)
32
33 if ctx is not self:
34 raise AssertionError(
35 f"Popped wrong request context. ({ctx!r} instead of {self!r})"
36 )