FastAPI 端点调试

  • 启动方式写入 main.py 文件内

  • vscode or pycharm 启用断点调试即可

# coding: utf8

from fastapi import FastAPI, BackgroundTasks
import time
import uvicorn

app = FastAPI()

def alter(email: str, msg = ""):
    time.sleep(5)
    print(email, msg)


@app.post('/send')
async def sendEmail(email: str, task: BackgroundTasks):
    task.add_task(alter, email, msg='不关注')
    return {"msg": '后台运行'}


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

Last updated