Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 8 of 8 for asynccontextmanager (0.1 sec)

  1. 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()
    
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Tue Mar 07 15:46:00 UTC 2023
    - 569 bytes
    - Viewed (0)
  2. tests/test_router_events.py

    
    def test_merged_mixed_state_lifespans() -> None:
        @asynccontextmanager
        async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
            yield
    
        @asynccontextmanager
        async def router_lifespan(app: FastAPI) -> AsyncGenerator[Dict[str, bool], None]:
            yield {"router": True}
    
        @asynccontextmanager
        async def sub_router_lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sat Aug 24 19:09:52 UTC 2024
    - 7.3K bytes
    - Viewed (0)
  3. 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,
    )
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Mon Dec 25 17:57:35 UTC 2023
    - 1.4K bytes
    - Viewed (0)
  4. 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; ๐Ÿ” โšซ๏ธ โฎ๏ธ ๐Ÿ.
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 8.6K bytes
    - Viewed (0)
  5. docs/em/docs/advanced/events.md

    ```Python hl_lines="14-19"
    {!../../docs_src/events/tutorial003.py!}
    ```
    
    ๐Ÿฅ‡ ๐Ÿ• ๐Ÿ”ข, โญ `yield`, ๐Ÿ”œ ๐Ÿ› ๏ธ **โญ** ๐Ÿˆธ โ–ถ๏ธ.
    
    &amp; ๐Ÿ• โฎ๏ธ `yield` ๐Ÿ”œ ๐Ÿ› ๏ธ **โฎ๏ธ** ๐Ÿˆธ โœ”๏ธ ๐Ÿ.
    
    ### ๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ
    
    ๐Ÿšฅ ๐Ÿ‘† โœ…, ๐Ÿ”ข ๐ŸŽ€ โฎ๏ธ `@asynccontextmanager`.
    
    ๐Ÿ‘ˆ ๐Ÿ—œ ๐Ÿ”ข ๐Ÿ”˜ ๐Ÿ•ณ ๐Ÿค™ "**๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ**".
    
    ```Python hl_lines="1  13"
    {!../../docs_src/events/tutorial003.py!}
    ```
    
    **๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ** ๐Ÿ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `with` ๐Ÿ“„, ๐Ÿ–ผ, `open()` ๐Ÿ’ช โš™๏ธ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ:
    
    ```Python
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 6.1K bytes
    - Viewed (0)
  6. docs/de/docs/advanced/events.md

    Und der Teil nach `yield` wird ausgefรผhrt, **nachdem** die Anwendung beendet ist.
    
    ### Asynchroner Kontextmanager
    
    Wie Sie sehen, ist die Funktion mit einem `@asynccontextmanager` versehen.
    
    Dadurch wird die Funktion in einen sogenannten โ€ž**asynchronen Kontextmanager**โ€œ umgewandelt.
    
    ```Python hl_lines="1  13"
    {!../../docs_src/events/tutorial003.py!}
    ```
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 9.1K bytes
    - Viewed (0)
  7. docs/pt/docs/advanced/events.md

    E a parte posterior do `yield` irรก executar **apรณs** a aplicaรงรฃo ser encerrada.
    
    ### Gerenciador de Contexto Assรญncrono
    
    Se vocรช verificar, a funรงรฃo estรก decorada com um `@asynccontextmanager`.
    
    Que converte a funรงรฃo em algo chamado de "**Gerenciador de Contexto Assรญncrono**".
    
    ```Python hl_lines="1  13"
    {!../../docs_src/events/tutorial003.py!}
    ```
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 8.6K bytes
    - Viewed (0)
  8. 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**".
    
    {* ../../docs_src/events/tutorial003.py hl[1,13] *}
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Mon Oct 28 10:36:22 UTC 2024
    - 7.6K bytes
    - Viewed (0)
Back to top