有没有办法从删除端点结束我在帖子中添加的fastapi backgroundtask?
例如:以fastapi教程中的示例为例:
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):
background_tasks.add_task(write_notification, email, message="some notification")
return {"message": "Notification sent in the background"}
什么是永久杀死所有未完成部分的正确方法 write_notifaction
作为后台任务添加的呼叫?
暂无答案!
目前还没有任何答案,快来回答吧!