コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 2 of about 2 for asynccontextmanager (0.001 sec.)
Lifespan Events 11228
Lifespan Events Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define logic (code) that should be executed before the application starts up . This means t ... and then see it in detail. We create an async function lifespan() with yield like this: Python 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI def fake_answer_to_everything_ml_model ( x : float ): return x * 42 ml_models = {} @asyncconte ... fining an async function with yield . This is very similar to Dependencies with yield . Python 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI def fake_answer_to_everything_ml_model ( x : float ): return x * 42 ml_models = {} @asyncconte ... executed before the application starts. And the part after the yield will be executed after the application has finished. Async Context Manager If you check, the function is decorated with an @asynccontextmanager . That converts the function into something called ...
https://man.mtool.work/fastapi/0.115/advanced/events/
yieldを持つ依存関係 7485
yieldを持つ依存関係 FastAPIは、いくつかの 終了後の追加のステップ を行う依存関係をサポートしています。 これを行うには、 return の代わりに yield を使い、その後に追加のステップを書きます。 豆知識 yield は必ず一度だけ使用するようにしてください。 ... インストールされます。 技術詳細 以下と一緒に使用できる関数なら何でも有効です: @contextlib.contextmanager または @contextlib.asynccontextmanager これらは FastAPI の依存関係として使用するのに有効です。 実際、FastAPIは内部的にこれら2つのデコレータを使用しています。 yie ... : yield db 豆知識 コンテキストマネージャを作成するもう一つの方法はwithです: @contextlib.contextmanager または @contextlib.asynccontextmanager これらを使って、関数を単一の yield でデコレートすることができます。 これは FastAPI が内部的に yield を持つ依存関係のために ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-with-yie...
PREV 1 NEXT