sanic-org/sanic

Graceful shutdown of signal handlers

Open

#2,369 opened on Jan 12, 2022

 (5 comments) (0 reactions) (1 assignee)Python (1,515 forks)batch import
beginnerhelp wanted

Repository metrics

Stars
 (17,623 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

When 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

Contributor guide