Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 15 for asynccontextmanager (0.32 sec)

  1. fastapi/concurrency.py

    from contextlib import asynccontextmanager as asynccontextmanager
    from typing import AsyncGenerator, ContextManager, TypeVar
    
    import anyio
    from anyio import CapacityLimiter
    from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
    from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
    from starlette.concurrency import (  # noqa
        run_until_first_complete as run_until_first_complete,
    )
    
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Mon Dec 25 17:57:35 GMT 2023
    - 1.4K bytes
    - Viewed (0)
  2. docs_src/events/tutorial003.py

    from contextlib import asynccontextmanager
    
    from fastapi import FastAPI
    
    
    def fake_answer_to_everything_ml_model(x: float):
        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()
    
    
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Mar 07 15:46:00 GMT 2023
    - 569 bytes
    - Viewed (0)
  3. tests/test_router_events.py

    from contextlib import asynccontextmanager
    from typing import AsyncGenerator, Dict
    
    import pytest
    from fastapi import APIRouter, FastAPI
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    
    class State(BaseModel):
        app_startup: bool = False
        app_shutdown: bool = False
        router_startup: bool = False
        router_shutdown: bool = False
        sub_router_startup: bool = False
        sub_router_shutdown: bool = False
    
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Wed Oct 18 12:36:40 GMT 2023
    - 3.2K bytes
    - Viewed (0)
  4. docs/ru/docs/tutorial/dependencies/dependencies-with-yield.md

        * <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
    
        будет корректно использоваться в качестве **FastAPI**-зависимости.
    
        На самом деле, FastAPI использует эту пару декораторов "под капотом".
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Apr 02 04:21:06 GMT 2024
    - 19.6K bytes
    - Viewed (0)
  5. docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md

        * <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
    
        都可以作为 **FastAPI** 的依赖项。
    
        实际上,FastAPI内部就使用了这两个装饰器。
    
    
    ## 使用 `yield` 的数据库依赖项
    
    例如,您可以使用这种方式创建一个数据库会话,并在完成后关闭它。
    
    在发送响应之前,只会执行 `yield` 语句及之前的代码:
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 10.3K bytes
    - Viewed (0)
  6. docs/de/docs/tutorial/dependencies/dependencies-with-yield.md

        * <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
    
        kann auch als gültige **FastAPI**-Abhängigkeit verwendet werden.
    
        Tatsächlich verwendet FastAPI diese beiden Dekoratoren intern.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat Mar 30 18:10:29 GMT 2024
    - 13.5K bytes
    - Viewed (0)
  7. docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md

        * <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
    
        これらは **FastAPI** の依存関係として使用するのに有効です。
    
        実際、FastAPIは内部的にこれら2つのデコレータを使用しています。
    
    ## `yield`を持つデータベースの依存関係
    
    例えば、これを使ってデータベースセッションを作成し、終了後にそれを閉じることができます。
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 12.5K bytes
    - Viewed (0)
  8. docs/en/docs/tutorial/dependencies/dependencies-with-yield.md

        * <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
    
        would be valid to use as a **FastAPI** dependency.
    
        In fact, FastAPI uses those two decorators internally.
    
    ## A database dependency with `yield`
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat Feb 24 23:06:37 GMT 2024
    - 14.1K bytes
    - Viewed (0)
  9. docs/em/docs/tutorial/dependencies/dependencies-with-yield.md

        * <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
    
        🔜 ☑ ⚙️ **FastAPI** 🔗.
    
        👐, FastAPI ⚙️ 📚 2️⃣ 👨‍🎨 🔘.
    
    ## 💽 🔗 ⏮️ `yield`
    
    🖼, 👆 💪 ⚙️ 👉 ✍ 💽 🎉 &amp; 🔐 ⚫️ ⏮️ 🏁.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 8.6K bytes
    - Viewed (0)
  10. docs/en/docs/advanced/events.md

    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 an "**async context manager**".
    
    ```Python hl_lines="1  13"
    {!../../../docs_src/events/tutorial003.py!}
    ```
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 7.8K bytes
    - Viewed (0)
Back to top