Graceful shutdown of signal handlers
See original GitHub issueWhen signals are added, we should run some sort of a cleanup like this on shutdown to make sure any custom signals are run. This also includes a suggestion that we identify them with a name: signal-XXXXX
.
async def cleanup(app, _):
for task in asyncio.all_tasks():
if task.get_name().startswith("signal"):
await task
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to handle signals with Go to graceful shutdown HTTP ...
Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then ...
Read more >Signal Handling — Gunicorn 20.1.0 documentation
TERM : Graceful shutdown. Waits for workers to finish their current requests up to the graceful_timeout. HUP : Reload the configuration, start the...
Read more >Graceful shutdowns on Cloud Run: Deep dive
The graceful termination signal is primarily sent to your application when it's scaling down container instances that are not getting traffic.
Read more >Implementing Graceful Shutdown in Go
Introducing signal handling · We need to use os.Interrupt to gracefully shutdown on Ctrl+C which is SIGINT · syscall. · Read more about...
Read more >Ruby Graceful Application Shutdown with SignalException ...
By default in most systems Graceful Shutdown implements by sending SIGTERM signal and 30 seconds delay before terminating the instance. How 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 FreeTop 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
Top GitHub Comments
Hi @ahopkins 👋 , I’m interested in taking this as my first issue! I have some ideas and questions which I will discuss below.
If I followed the flow correctly, I believe the task for signal handlers gets created in the
sanic.signals.SignalRouter.dispatch
method. In which case, a name could be assigned to the task like so:task = asyncio.get_running_loop().create_task(dispatch, name="signal")
For the
XXXXX
part of the signal task’s name, what were you thinking of passing here?For the running of signal tasks on shutdown, I was thinking that a new method could be added to
sanic.app.Sanic
that’s similar to thesanic.app.Sanic.shutdown_tasks
method. This method would then be called in thesanic.mixins.runner.RunnerMixin.stop
method to run the signal tasks on shutdown. Is this approach similar to what you were looking for?How are you distinguishing these?
I am hesitant to do this because it may or may not be desirable. If anything it should be controllable by config.