-
Hi all, First, many thanks for this wonderful library! I'm using starlette/starlette/background.py Lines 42 to 43 in 93494a4 I'm empathetic to #549 (comment) ("users should deal with the concurrency themselves if that's not what they want."), and I see users could write their own wrappers as in #549 (comment). But, as a user, I may humbly suggest: I would be delighted if I could pass a (also related: #1589) Many thanks for your consideration, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If it helps here's a full-fledged implementation of BackgroundTasks that you could use with FastAPI: https://github.com/adriangb/asgi-background |
Beta Was this translation helpful? Give feedback.
-
Thank you for the reply, @adriangb ! My own implementation is much more barebones, just swapping in the class ConcurrentBackgroundTasks(BackgroundTasks):
async def __call__(self) -> None:
await asyncio.gather(*[task() for task in self.tasks]) This has worked in my preliminary testing. Admittedly, the reason I'd love for this implementation to be an option with a # Doesn't work; still constructed as BackgroundTasks
@app.post("/foo")
def foo(background_tasks: ConcurrentBackgroundTasks):
pass
# Works, but we must now manually add schema and validation features
@app.post("/foo", response_model=Model)
def foo():
bgt = ConcurrentBackgroundTasks()
bgt.add_task(...)
return JSONResponse(
content=jsonable_encoder(
Model(...)
),
background=bgt,
) If a native I'll open an issue on FastAPI too. It would be a great start if starlette exposed this API. |
Beta Was this translation helpful? Give feedback.
If it helps here's a full-fledged implementation of BackgroundTasks that you could use with FastAPI: https://github.com/adriangb/asgi-background