Skip to content

Singular hypercorn before/after hook #339

@sky-cake

Description

@sky-cake

Does hypercorn have before/on_start and after/on_end async hooks that don't get called for each worker spawned? If not, how do you suggest achieving this?

Here is a POC,

from asyncio import sleep
from quart import Quart

app = Quart(__name__)

@app.route('/')
async def hello():
    return 'hello'

@app.before_serving
async def on_start():
    await sleep(0.01)
    print('Wish to only print once, on start')

@app.after_serving
async def on_end():
    await sleep(0.01)
    print('Wish to only print once, on end')

hypercorn -w 3 -b 0.0.0.0:5000 poc:app

Wish to only print once, on start
Wish to only print once, on start
[2026-01-03 13:26:54 +0800] [112664] [INFO] Running on http://0.0.0.0:5000 (CTRL + C to quit)
[2026-01-03 13:26:54 +0800] [112662] [INFO] Running on http://0.0.0.0:5000 (CTRL + C to quit)
Wish to be only print once, on start
[2026-01-03 13:26:54 +0800] [112663] [INFO] Running on http://0.0.0.0:5000 (CTRL + C to quit)
^CWish to only print once, on end
Wish to only print once, on end
Wish to only print once, on end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions