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
Provenance
- Commit
8239765- Tree
6366d43- Author
pgjones <philip.graham.jones@googlemail.com>- Committer
David Lord <davidism@gmail.com>- Parent
a05c0c6
5 files changed+25 added−12 removed
modified:src/flask/app.py+7 added-5 removed
1387 unmodified lines1388 1389 .. 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"]1394 1395 if propagate is None:1396 propagate = self.testing or self.debug95 unmodified lines1492 """1493 self._got_first_request = True1494 1495 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 lines1520 """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 lines2053 if name in self.teardown_request_funcs:2054 for func in reversed(self.teardown_request_funcs[name]):2055 self.ensure_sync(func)(exc)2056 2055- request_tearing_down.send(self, exc=exc)2057+ request_tearing_down.send(self, _async_wrapper=self.ensure_sync, exc=exc)2058 2059 def do_teardown_appcontext(2060 self, exc: t.Optional[BaseException] = _sentinel # type: ignore2061 ) -> None:16 unmodified lines2078 2079 for func in reversed(self.teardown_appcontext_funcs):2080 self.ensure_sync(func)(exc)2081 2080- appcontext_tearing_down.send(self, exc=exc)2082+ appcontext_tearing_down.send(self, _async_wrapper=self.ensure_sync, exc=exc)2083 2084 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 linesmodified:src/flask/ctx.py+2 added-2 removed
240 unmodified lines241 242 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)246 247 def pop(self, exc: t.Optional[BaseException] = _sentinel) -> None: # type: ignore248 """Pops the app context."""249 try:9 unmodified lines259 raise AssertionError(260 f"Popped wrong app context. ({ctx!r} instead of {self!r})"261 )262 263- appcontext_popped.send(self.app)263+ appcontext_popped.send(self.app, _async_wrapper=self.app.ensure_sync)264 265 def __enter__(self) -> "AppContext":266 self.push()267 return self171 unmodified linesmodified:src/flask/helpers.py+3 added-1 removed
325 unmodified lines326 # 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 linesmodified:src/flask/templating.py+12 added-4 removed
124 unmodified lines125 126 127 def _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 rv137 138 139 def render_template(26 unmodified lines166 def _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+ )173 174 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+ )179 180 rv = generate()181 182 # If a request context is active, keep it while generating.38 unmodified linesmodified:CHANGES.rst+1 added
28 unmodified lines29 - 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