| 286 | |
| 287 | @click.pass_context |
| 288 | def decorator(__ctx: click.Context, *args: Any, **kwargs: Any) -> Any: |
| 289 | async def _inner() -> Any: |
| 290 | async with __ctx.ensure_object(ScriptInfo).load_app().app_context(): |
| 291 | try: |
| 292 | return __ctx.invoke(fn, *args, **kwargs) |
| 293 | except RuntimeError as error: |
| 294 | if ( |
| 295 | error.args[0] |
| 296 | == "Cannot run the event loop while another loop is running" |
| 297 | ): |
| 298 | click.echo( |
| 299 | "The appcontext cannot be used with a command that" |
| 300 | " runs an event loop. See quart#361 for more details" |
| 301 | ) |
| 302 | raise |
| 303 | |
| 304 | return asyncio.run(_inner()) |
| 305 | |
| 306 | return functools.update_wrapper(decorator, fn) |
| 307 | |