- Sort Score
- Result 10 results
- Languages All
Results 1 - 10 of 25 for Lifespan (0.05 sec)
-
docs_src/app_testing/tutorial004_py39.py
@asynccontextmanager async def lifespan(app: FastAPI): items["foo"] = {"name": "Fighters"} items["bar"] = {"name": "Tenders"} yield # clean up items items.clear() app = FastAPI(lifespan=lifespan) @app.get("/items/{item_id}") async def read_items(item_id: str): return items[item_id] def test_read_items(): # Before the lifespan starts, "items" is still emptyRegistered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 1.2K bytes - Viewed (0) -
docs/de/docs/advanced/events.md
Weitere Informationen zu Starlettes `lifespan`-Handlern finden Sie in <a href="https://www.starlette.dev/lifespan/" class="external-link" target="_blank">Starlettes Lifespan-Dokumentation</a>. Einschließlich, wie man Lifespan-Zustand handhabt, der in anderen Bereichen Ihres Codes verwendet werden kann. /// ## Unteranwendungen { #sub-applications }
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 9.5K bytes - Viewed (0) -
docs/en/docs/advanced/testing-events.md
# Testing Events: lifespan and startup - shutdown { #testing-events-lifespan-and-startup-shutdown } When you need `lifespan` to run in your tests, you can use the `TestClient` with a `with` statement: {* ../../docs_src/app_testing/tutorial004_py39.py hl[9:15,18,27:28,30:32,41:43] *} You can read more details about the ["Running lifespan in tests in the official Starlette documentation site."](https://www.starlette.dev/lifespan/#running-lifespan-in-tests)Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 626 bytes - Viewed (0) -
tests/test_router_events.py
yield {"sub_router": True} state.sub_router_shutdown = True sub_router = APIRouter(lifespan=subrouter_lifespan) router = APIRouter(lifespan=router_lifespan) router.include_router(sub_router) app = FastAPI(lifespan=lifespan) app.include_router(router) @app.get("/") def main(request: Request) -> dict[str, str]: assert request.state.appRegistered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 21:25:59 UTC 2025 - 7.3K bytes - Viewed (0) -
docs/en/docs/advanced/events.md
/// info You can read more about the Starlette `lifespan` handlers in <a href="https://www.starlette.dev/lifespan/" class="external-link" target="_blank">Starlette's Lifespan' docs</a>. Including how to handle lifespan state that can be used in other areas of your code. /// ## Sub Applications { #sub-applications }
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 7.9K bytes - Viewed (0) -
docs/pt/docs/advanced/events.md
Você pode ler mais sobre os manipuladores de `lifespan` do Starlette na <a href="https://www.starlette.dev/lifespan/" class="external-link" target="_blank">Documentação do Lifespan do Starlette</a>. Incluindo como lidar com estado do lifespan que pode ser usado em outras áreas do seu código. /// ## Sub Aplicações { #sub-applications }
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 8.8K bytes - Viewed (0) -
docs/zh/docs/advanced/events.md
你可以在模块/文件的顶部加载它,但这也意味着即使你只是在运行一个简单的自动化测试,它也会**加载模型**,这样测试将**变慢**,因为它必须在能够独立运行代码的其他部分之前等待模型加载完成。 这就是我们要解决的问题——在处理请求前加载模型,但只是在应用开始接收请求前,而不是代码执行时。 ## 生命周期 lifespan 你可以使用`FastAPI()`应用的`lifespan`参数和一个上下文管理器(稍后我将为你展示)来定义**启动**和**关闭**的逻辑。 让我们从一个例子开始,然后详细介绍。 我们使用`yield`创建了一个异步函数`lifespan()`像这样: ```Python hl_lines="16 19" {!../../docs_src/events/tutorial003.py!} ```
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Oct 11 17:48:49 UTC 2025 - 7K bytes - Viewed (0) -
docs_src/events/tutorial003_py39.py
return x * 42 ml_models = {} @asynccontextmanager async def lifespan(app: FastAPI): # Load the ML model ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model yield # Clean up the ML models and release the resources ml_models.clear() app = FastAPI(lifespan=lifespan) @app.get("/predict") async def predict(x: float):Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 569 bytes - Viewed (0) -
docs/ru/docs/advanced/testing-events.md
Если вам нужно, чтобы `lifespan` выполнялся в ваших тестах, вы можете использовать `TestClient` вместе с оператором `with`: {* ../../docs_src/app_testing/tutorial004_py39.py hl[9:15,18,27:28,30:32,41:43] *}Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 902 bytes - Viewed (0) -
docs/es/docs/advanced/testing-events.md
Cuando necesitas que `lifespan` se ejecute en tus tests, puedes usar el `TestClient` con un statement `with`: {* ../../docs_src/app_testing/tutorial004_py39.py hl[9:15,18,27:28,30:32,41:43] *} Puedes leer más detalles sobre ["Ejecutar lifespan en tests en el sitio oficial de documentación de Starlette."](https://www.starlette.dev/lifespan/#running-lifespan-in-tests)Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 632 bytes - Viewed (0)