- Sort Score
- Num 10 results
- Language All
Results 1 - 10 of 20 for BackgroundTasks (0.08 seconds)
-
docs/en/docs/tutorial/background-tasks.md
## Using `BackgroundTasks` { #using-backgroundtasks } First, import `BackgroundTasks` and define a parameter in your *path operation function* with a type declaration of `BackgroundTasks`: {* ../../docs_src/background_tasks/tutorial001_py310.py hl[1,13] *} **FastAPI** will create the object of type `BackgroundTasks` for you and pass it as that parameter.Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 05 18:13:19 GMT 2026 - 4.7K bytes - Click Count (0) -
fastapi/background.py
from collections.abc import Callable from typing import Annotated, Any from annotated_doc import Doc from starlette.background import BackgroundTasks as StarletteBackgroundTasks from typing_extensions import ParamSpec P = ParamSpec("P") class BackgroundTasks(StarletteBackgroundTasks): """ A collection of background tasks that will be called after a response has been sent to the client. Read more about it in the
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Wed Feb 11 18:41:21 GMT 2026 - 1.8K bytes - Click Count (0) -
docs/zh/docs/tutorial/background-tasks.md
* 处理数据: * 例如,假设您收到的文件必须经过一个缓慢的过程,您可以返回一个"Accepted"(HTTP 202)响应并在后台处理它。 ## 使用 `BackgroundTasks` { #using-backgroundtasks } 首先导入 `BackgroundTasks` 并在 *路径操作函数* 中使用类型声明 `BackgroundTasks` 定义一个参数: {* ../../docs_src/background_tasks/tutorial001_py310.py hl[1,13] *} **FastAPI** 会创建一个 `BackgroundTasks` 类型的对象并作为该参数传入。 ## 创建一个任务函数 { #create-a-task-function } 创建要作为后台任务运行的函数。 它只是一个可以接收参数的标准函数。Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 17:06:37 GMT 2026 - 4.1K bytes - Click Count (0) -
tests/test_response_dependency.py
assert resp.status_code == 200 assert resp.json() == {"path": "/", "user_agent": "test-agent"} # Tests for BackgroundTasks type hint with Depends def test_background_tasks_with_depends_annotated(): """BackgroundTasks type hint should work with Annotated[BackgroundTasks, Depends(...)].""" app = FastAPI() task_results = [] def background_task(message: str):Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 05 18:23:16 GMT 2026 - 5.2K bytes - Click Count (0) -
docs/ja/docs/tutorial/background-tasks.md
* データ処理: * たとえば、時間のかかる処理を必要とするファイル受信時には、「Accepted」(HTTP 202) のレスポンスを返し、バックグラウンドで処理できます。 ## `BackgroundTasks` の使用 { #using-backgroundtasks } まず初めに、`BackgroundTasks` をインポートし、`BackgroundTasks` の型宣言と共に、*path operation function* のパラメーターを定義します: {* ../../docs_src/background_tasks/tutorial001_py310.py hl[1,13] *} **FastAPI** は、`BackgroundTasks` 型のオブジェクトを作成し、そのパラメーターに渡します。 ## タスク関数の作成 { #create-a-task-function }Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 14:07:17 GMT 2026 - 5.8K bytes - Click Count (0) -
docs/zh-hant/docs/tutorial/background-tasks.md
* 處理資料: * 例如,收到一個需要經過較慢處理流程的檔案時,你可以先回應「Accepted」(HTTP 202),再在背景處理該檔案。 ## 使用 `BackgroundTasks` { #using-backgroundtasks } 首先,匯入 `BackgroundTasks`,並在你的路徑操作函式中定義一個型別為 `BackgroundTasks` 的參數: {* ../../docs_src/background_tasks/tutorial001_py310.py hl[1,13] *} **FastAPI** 會為你建立 `BackgroundTasks` 物件,並以該參數傳入。 ## 建立任務函式 { #create-a-task-function } 建立一個作為背景任務執行的函式。 它只是個可接收參數的一般函式。Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 17:05:38 GMT 2026 - 4.1K bytes - Click Count (0) -
docs/en/docs/reference/background.md
# Background Tasks - `BackgroundTasks` You can declare a parameter in a *path operation function* or dependency function with the type `BackgroundTasks`, and then you can use it to schedule the execution of background tasks after the response is sent. You can import it directly from `fastapi`: ```python from fastapi import BackgroundTasks ```
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Apr 18 19:53:19 GMT 2024 - 377 bytes - Click Count (0) -
fastapi/__init__.py
__version__ = "0.135.3" from starlette import status as status from .applications import FastAPI as FastAPI from .background import BackgroundTasks as BackgroundTasks from .datastructures import UploadFile as UploadFile from .exceptions import HTTPException as HTTPException from .exceptions import WebSocketException as WebSocketException from .param_functions import Body as Body
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Wed Apr 01 16:21:01 GMT 2026 - 1.1K bytes - Click Count (0) -
docs_src/background_tasks/tutorial001_py310.py
from fastapi import BackgroundTasks, FastAPI app = FastAPI() def write_notification(email: str, message=""): with open("log.txt", mode="w") as email_file: content = f"notification for {email}: {message}" email_file.write(content) @app.post("/send-notification/{email}") async def send_notification(email: str, background_tasks: BackgroundTasks):
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 519 bytes - Click Count (0) -
tests/test_dependency_contextmanager.py
import json import pytest from fastapi import BackgroundTasks, Depends, FastAPI from fastapi.responses import StreamingResponse from fastapi.testclient import TestClient app = FastAPI() state = { "/async": "asyncgen not started", "/sync": "generator not started", "/async_raise": "asyncgen raise not started", "/sync_raise": "generator raise not started", "context_a": "not started a", "context_b": "not started b",
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Wed Dec 17 21:25:59 GMT 2025 - 11.5K bytes - Click Count (0)