question 390 Async Python · hard
Per-request timeouts inside an overall deadline
A status page checks many services at once. Each check may take at most per_check seconds, and the whole page must be ready within total seconds. Write status_page(services, check, per_check, total): run every check concurrently; return a dictionary from service to its result, "slow" when its own timeout hit, "error" when it raised, or "unknown" when the overall deadline arrived first.
Coroutine
async def status_page(services, check, per_check, total)Per check
await check(service) limited to per_check seconds → result, "slow", or "error" (any exception)Overallafter
total seconds, every unfinished service is "unknown", its check cancelled; the coroutine returns by then