[QUESTION] Any plan to suppprt BackgroundTask from Starlette?
See original GitHub issueStarlette allows to attach a list of background tasks to a response, that will run only once the response has been sent. If the task is a not a coroutine is it executed on a specific executor to not block the event loop.
if task.is_coroutine():
future = asyncio.ensure_future(task())
else:
loop = asyncio.get_event_loop()
future = await loop.run_in_executor(None, task.func)
Is there any possibility to add this great feature to Fastai ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Background Tasks - Starlette
Starlette includes a BackgroundTask class for in-process background tasks. A background task should be attached to a response, and will run only once...
Read more >How to use background tasks with Starlette when there's no ...
Solved! Starlette Middleware: class BackgroundTaskMiddleware(BaseHTTPMiddleware): async def dispatch( self, request: Request, ...
Read more >Quick and dirty mock service with Starlette - DEV Community
The Problem: Run a mocked third party service with a delayed webhook ... feature that I saw in the Starlette documentation: Background Tasks....
Read more >backgroundTask in SwiftUI cannot compile - Apple Developer
In my case, this doesn't help. Indeed my app is only an iPhone and iPad app, no macOS. Regardless, I tried your code...
Read more >[Python] FastAPI async endpoint with an async background task
As this is a web endpoint that spawns background tasks, ... indeed points to a problem with our instrumentation, they are going to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@madkote if your processing is in an async function (let’s say, created with
async def process_something(): ...
), you can use an async function for your path operation too, and inside of it, useawait process_something()
.If it’s a normal function, you can use
run_in_threadpool
from Starlette, pass your standard function and await it, something like:If that doesn’t solve your problem, please create a new issue for it so we can continue the discussion there.
As the original issue should be solved now with the support for
BackgroundTasks
, I’ll close it now. But feel free to add more comments or create new issues.@tiangolo thanks for the reply, I ended up adding more features to my project just to justify celery 😄