question 386 Async Python · medium
Fix the worker that can't be stopped
At shutdown the server cancels its background heartbeat task and waits for it, but the task never reports as cancelled: it catches the cancellation, logs it, and returns normally. Fix it so it still logs "stopped" but ends cancelled.
Coroutine
async def heartbeat(log, every): appends "beat" every every seconds foreverOn cancellationappend
"stopped", then let the cancellation continue (the task ends cancelled)