Proposal: Pluggable Background Task Runners for FastAPI (free-threaded Python 3.14 aware; optional Celery-like backend) #14154
Unanswered
mahimairaja
asked this question in
Questions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
Motivation
Python 3.14 introduces an officially supported free-threaded build (no GIL) which enables true parallelism across threads for pure-Python CPU-bound workloads when that build is used. Meanwhile, FastAPI’s BackgroundTasks (via Starlette) are in-process, sequential, and non-durable: they run only after the response, execute in order, and if one raises, the rest don’t run. The docs recommend Celery/RQ/etc. for heavier use cases. With more teams experimenting with the free-threaded interpreter, there’s demand for a path that (a) keeps FastAPI’s ergonomics, (b) allows concurrent post-response work safely, and (c) offers an official integration point for durable, multi-process/cluster workers without forcing a specific queue.
Proposal.
Introduce a small, optional abstraction:
Why in FastAPI (not only Starlette)?
The Starlette docs define background tasks as in-process and sequential; that’s perfect for the framework layer. FastAPI can provide developer-experience sugar (config + protocol) and official adapters/docs, while leaving the underlying execution primitives to Starlette/AnyIO.
Backwards compatibility.
No breaking changes: current BackgroundTasks keeps today’s sequential in-process semantics unless the new flags are used
Operating System
Linux, Windows, macOS
Operating System Details
Need to check for each OS
FastAPI Version
Pydantic Version
Python Version
v3.14
Additional Context
Python 3.14 Official: https://docs.python.org/3.14/whatsnew/3.14.html
Blog on Python 3.14: https://medium.com/towards-artificial-intelligence/python-3-14-6a94d2b5af3f?sk=0a7891cbe60d80724a76f02e1b78d3ca
FastAPI Background Tasks docs: https://fastapi.tiangolo.com/tutorial/background-tasks/
Starlette Background Tasks: https://www.starlette.dev/background/
Starlette threadpool behavior: https://www.starlette.dev/threadpool/
sys._is_gil_enabled()— added in 3.14 to detect whether the GIL is active: https://docs.python.org/3.14/whatsnew/changelog.htmlAll reactions