Skip to content

Instantly share code, notes, and snippets.

@CodeWithOz
Last active October 9, 2025 05:36
Show Gist options
  • Select an option

  • Save CodeWithOz/d31e788d4bec21eec47a3247e593163e to your computer and use it in GitHub Desktop.

Select an option

Save CodeWithOz/d31e788d4bec21eec47a3247e593163e to your computer and use it in GitHub Desktop.
Code snippets showing different approaches to resolving blocking operations in a FastAPI server.
...
async def upload_to_s3():
await do_async_work_to_prepare_for_the_upload()
# assume the upload will run asynchronously for 5 seconds, such as
# when using aioboto3 (unofficial async-compatible aws sdk)
logger.info("Before sleep")
await asyncio.sleep(5)
logger.info("After sleep")
@app.get("/process-files")
async def process_files(background_tasks: BackgroundTasks):
logger.info("Before process files")
background_tasks.add_task(upload_to_s3)
logger.info("After process files")
return {"ok": True}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment