Skip to content

Instantly share code, notes, and snippets.

@topicus
Created May 8, 2023 14:52
Show Gist options
  • Save topicus/3ee91458917e5f6bf0136a5f489f6916 to your computer and use it in GitHub Desktop.
Save topicus/3ee91458917e5f6bf0136a5f489f6916 to your computer and use it in GitHub Desktop.
import asyncio
from fastapi import FastAPI
app = FastAPI()
async def some_long_running_task(param):
await asyncio.sleep(10) # Simulating a long-running task
print(f"Task completed with param: {param}")
@app.get("/fire-and-forget/{param}")
async def fire_and_forget(param: str):
asyncio.create_task(some_long_running_task(param))
return {"message": "Task has been started."}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8010)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment