Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 41 - 50 of 1,038 for Async (0.21 seconds)

  1. docs/zh-hant/docs/advanced/stream-data.md

    在這個範例中因為是存在記憶體的假檔案(`io.BytesIO`),影響不大;但若是實際檔案,務必在處理完成後關閉檔案。
    
    ### 檔案與 Async { #files-and-async }
    
    多數情況下,類檔案物件預設不相容於 async/await。
    
    例如,它們沒有 `await file.read()`,也不支援 `async for chunk in file`。
    
    而且在許多情況下,讀取它們會是阻塞操作(可能阻塞事件迴圈),因為資料是從磁碟或網路讀取。
    
    /// info
    
    上面的範例其實是例外,因為 `io.BytesIO` 物件已在記憶體中,讀取不會阻塞任何東西。
    
    但在多數情況下,讀取檔案或類檔案物件會造成阻塞。
    
    ///
    
    為了避免阻塞事件迴圈,你可以將路徑操作函式宣告為一般的 `def`(而非 `async def`),這樣 FastAPI 會在 threadpool worker 上執行它,避免阻塞主事件迴圈。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:33:04 GMT 2026
    - 4.9K bytes
    - Click Count (0)
  2. guava-tests/test/com/google/common/util/concurrent/SettableFutureTest.java

      public void testCancel_beforeSet() throws Exception {
        SettableFuture<Object> async = SettableFuture.create();
        async.cancel(true);
        assertFalse(async.set(42));
      }
    
      public void testCancel_multipleBeforeSetFuture_noInterruptFirst() throws Exception {
        SettableFuture<Object> async = SettableFuture.create();
        async.cancel(false);
        async.cancel(true);
        SettableFuture<Object> inner = SettableFuture.create();
    Created: Fri Apr 03 12:43:13 GMT 2026
    - Last Modified: Mon Mar 16 22:45:21 GMT 2026
    - 7.4K bytes
    - Click Count (0)
  3. docs_src/stream_data/tutorial002_py310.py

        media_type = "image/png"
    
    
    @app.get("/image/stream", response_class=PNGStreamingResponse)
    async def stream_image() -> AsyncIterable[bytes]:
        with read_image() as image_file:
            for chunk in image_file:
                yield chunk
    
    
    @app.get("/image/stream-no-async", response_class=PNGStreamingResponse)
    def stream_image_no_async() -> Iterable[bytes]:
        with read_image() as image_file:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Feb 27 20:51:40 GMT 2026
    - 5.6K bytes
    - Click Count (0)
  4. tests/test_dependency_cache.py

    counter_holder = {"counter": 0}
    
    
    async def dep_counter():
        counter_holder["counter"] += 1
        return counter_holder["counter"]
    
    
    async def super_dep(count: int = Depends(dep_counter)):
        return count
    
    
    @app.get("/counter/")
    async def get_counter(count: int = Depends(dep_counter)):
        return {"counter": count}
    
    
    @app.get("/sub-counter/")
    async def get_sub_counter(
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Tue Aug 23 13:30:24 GMT 2022
    - 2.7K bytes
    - Click Count (0)
  5. tests/test_dependency_yield_scope_websockets.py

    ]
    
    app = FastAPI()
    
    
    @app.websocket("/function-scope")
    async def function_scope(websocket: WebSocket, session: SessionFuncDep) -> Any:
        await websocket.accept()
        await websocket.send_json({"is_open": session.open})
    
    
    @app.websocket("/request-scope")
    async def request_scope(websocket: WebSocket, session: SessionRequestDep) -> Any:
        await websocket.accept()
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 17 21:25:59 GMT 2025
    - 6K bytes
    - Click Count (0)
  6. tests/test_stringified_annotation_dependency.py

    if TYPE_CHECKING:  # pragma: no cover
        from collections.abc import AsyncGenerator
    
    
    class DummyClient:
        async def get_people(self) -> list:
            return ["John Doe", "Jane Doe"]
    
        async def close(self) -> None:
            pass
    
    
    async def get_client() -> AsyncGenerator[DummyClient, None]:
        client = DummyClient()
        yield client
        await client.close()
    
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 17 21:25:59 GMT 2025
    - 2.2K bytes
    - Click Count (0)
  7. tests/test_stream_bare_type.py

    
    app = FastAPI()
    
    
    @app.get("/items/stream-bare-async")
    async def stream_bare_async() -> AsyncIterable:
        yield {"name": "foo"}
    
    
    @app.get("/items/stream-bare-sync")
    def stream_bare_sync() -> Iterable:
        yield {"name": "bar"}
    
    
    client = TestClient(app)
    
    
    def test_stream_bare_async_iterable():
        response = client.get("/items/stream-bare-async")
        assert response.status_code == 200
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Feb 27 18:56:47 GMT 2026
    - 1.1K bytes
    - Click Count (0)
  8. docs_src/dependencies/tutorial012_py310.py

    from fastapi import Depends, FastAPI, Header, HTTPException
    
    
    async def verify_token(x_token: str = Header()):
        if x_token != "fake-super-secret-token":
            raise HTTPException(status_code=400, detail="X-Token header invalid")
    
    
    async def verify_key(x_key: str = Header()):
        if x_key != "fake-super-secret-key":
            raise HTTPException(status_code=400, detail="X-Key header invalid")
        return x_key
    
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 696 bytes
    - Click Count (0)
  9. docs_src/security/tutorial005_py310.py

                )
        return user
    
    
    async def get_current_active_user(
        current_user: User = Security(get_current_user, scopes=["me"]),
    ):
        if current_user.disabled:
            raise HTTPException(status_code=400, detail="Inactive user")
        return current_user
    
    
    @app.post("/token")
    async def login_for_access_token(
        form_data: OAuth2PasswordRequestForm = Depends(),
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 18:10:35 GMT 2026
    - 5.3K bytes
    - Click Count (0)
  10. docs_src/custom_docs_ui/tutorial001_py310.py

        )
    
    
    @app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
    async def swagger_ui_redirect():
        return get_swagger_ui_oauth2_redirect_html()
    
    
    @app.get("/redoc", include_in_schema=False)
    async def redoc_html():
        return get_redoc_html(
            openapi_url=app.openapi_url,
            title=app.title + " - ReDoc",
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 1.1K bytes
    - Click Count (0)
Back to Top