Remove processed background task objects #2546
Unanswered
jainal09
asked this question in
Potential Issue
Replies: 2 comments 1 reply
-
I don’t see a problem with the change. I don’t think you need the But you could also use your own background task system. Here’s an example https://github.com/adriangb/asgi-background |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This discussion is based on #2542
Summary
When a background task is processed it is not removed from the array and it is very difficult to implement features in which we want to find length of queued background tasks
This can be used to freeze shutdowns when handling OS signals for enabling graceful shutdowns. Thus, if there are already enqueued background tasks wait and only then stop the server once all the tasks are finished.
The reason, for this is because once the task is processed in await task(), why is there a need to keep it in the list. I am removing it because, I want to achieve something like this
If I want to fetch the current task queue length
using something like below
This is helpful for graceful shutdown of the application in scenarios where a lots of bg task are enqueued and now you intercepted a SIGTERM or SIGKILL which sends a termination signal but, the server will not be stopped until all the enqueued tasks are processed.
So, I propose to change the
starlette/background.py
Line 43
Beta Was this translation helpful? Give feedback.
All reactions