Skip to content
Myr

allow async signal receivers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by pgjones · committed by David Lord · parent a05c0c6 · Browse files · 5 files+25 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+25 added−12 removed

  • other:+25 added−12 removed

5 files+25 added−12 removed

modified:src/flask/app.py+7 added-5 removed
1387 unmodified lines
13881389 .. versionadded:: 0.31390 """1391 exc_info = sys.exc_info()1392 got_request_exception.send(self, exception=e)1392 got_request_exception.send(self, _async_wrapper=self.ensure_sync, exception=e)1393 propagate = self.config["PROPAGATE_EXCEPTIONS"]13941395 if propagate is None:1396 propagate = self.testing or self.debug
95 unmodified lines
1492 """1493 self._got_first_request = True14941495 try:1496 request_started.send(self)1496 request_started.send(self, _async_wrapper=self.ensure_sync)1497 rv = self.preprocess_request()1498 if rv is None:1499 rv = self.dispatch_request()1500 except Exception as e:
19 unmodified lines
1520 """1521 response = self.make_response(rv)1522 try:1523 response = self.process_response(response)1524 request_finished.send(self, response=response)1524 request_finished.send(1525 self, _async_wrapper=self.ensure_sync, response=response1526 )1527 except Exception:1528 if not from_error_handler:1529 raise1530 self.logger.exception(
522 unmodified lines
2053 if name in self.teardown_request_funcs:2054 for func in reversed(self.teardown_request_funcs[name]):2055 self.ensure_sync(func)(exc)20562055 request_tearing_down.send(self, exc=exc)2057 request_tearing_down.send(self, _async_wrapper=self.ensure_sync, exc=exc)20582059 def do_teardown_appcontext(2060 self, exc: t.Optional[BaseException] = _sentinel # type: ignore2061 ) -> None:
16 unmodified lines
20782079 for func in reversed(self.teardown_appcontext_funcs):2080 self.ensure_sync(func)(exc)20812080 appcontext_tearing_down.send(self, exc=exc)2082 appcontext_tearing_down.send(self, _async_wrapper=self.ensure_sync, exc=exc)20832084 def app_context(self) -> AppContext:2085 """Create an :class:`~flask.ctx.AppContext`. Use as a ``with``2086 block to push the context, which will make :data:`current_app`
144 unmodified lines
modified:src/flask/ctx.py+2 added-2 removed
240 unmodified lines
241242 def push(self) -> None:243 """Binds the app context to the current context."""244 self._cv_tokens.append(_cv_app.set(self))245 appcontext_pushed.send(self.app)245 appcontext_pushed.send(self.app, _async_wrapper=self.app.ensure_sync)246247 def pop(self, exc: t.Optional[BaseException] = _sentinel) -> None: # type: ignore248 """Pops the app context."""249 try:
9 unmodified lines
259 raise AssertionError(260 f"Popped wrong app context. ({ctx!r} instead of {self!r})"261 )262263 appcontext_popped.send(self.app)263 appcontext_popped.send(self.app, _async_wrapper=self.app.ensure_sync)264265 def __enter__(self) -> "AppContext":266 self.push()267 return self
171 unmodified lines
modified:src/flask/helpers.py+3 added-1 removed
325 unmodified lines
326 # implementations that use external storage for keeping their keys/values.327 flashes = session.get("_flashes", [])328 flashes.append((category, message))329 session["_flashes"] = flashes330 app = current_app._get_current_object() # type: ignore331 message_flashed.send(331 current_app._get_current_object(), # type: ignore332 app,333 _async_wrapper=app.ensure_sync,334 message=message,335 category=category,336 )337
359 unmodified lines
modified:src/flask/templating.py+12 added-4 removed
124 unmodified lines
125126127def _render(app: "Flask", template: Template, context: t.Dict[str, t.Any]) -> str:128 app.update_template_context(context)129 before_render_template.send(app, template=template, context=context)129 before_render_template.send(130 app, _async_wrapper=app.ensure_sync, template=template, context=context131 )132 rv = template.render(context)131 template_rendered.send(app, template=template, context=context)133 template_rendered.send(134 app, _async_wrapper=app.ensure_sync, template=template, context=context135 )136 return rv137138139def render_template(
26 unmodified lines
166def _stream(167 app: "Flask", template: Template, context: t.Dict[str, t.Any]168) -> t.Iterator[str]:169 app.update_template_context(context)166 before_render_template.send(app, template=template, context=context)170 before_render_template.send(171 app, _async_wrapper=app.ensure_sync, template=template, context=context172 )173174 def generate() -> t.Iterator[str]:175 yield from template.generate(context)170 template_rendered.send(app, template=template, context=context)176 template_rendered.send(177 app, _async_wrapper=app.ensure_sync, template=template, context=context178 )179180 rv = generate()181182 # If a request context is active, keep it while generating.
38 unmodified lines
modified:CHANGES.rst+1 added
28 unmodified lines
29- The ``locked_cached_property`` decorator is deprecated. Use a lock inside the30 decorated function if locking is needed. :issue:`4993`31- Signals are always available. ``blinker>=1.6.2`` is a required dependency. The32 ``signals_available`` attribute is deprecated. :issue:`5056`33- Signals support ``async`` subscriber functions. :pr:`5049`34- Remove uses of locks that could cause requests to block each other very briefly.35 :issue:`4993`36- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.37 :pr:`4947`
1436 unmodified lines