runtime
387 / 500
question 387 Async Python · medium

Poll a job until it is ready, with a deadline

A report service starts a job and you poll is_ready() until it says yes. Write wait_until_ready(is_ready, interval, deadline): await is_ready(); if it isn't ready, sleep interval seconds and ask again. Return how many times you asked. If the job isn't ready within deadline seconds, raise TimeoutError (without asking again after the deadline).

Coroutineasync def wait_until_ready(is_ready, interval, deadline)
Returnsthe number of is_ready() calls made, including the one that returned True
RaisesTimeoutError at deadline seconds if it never became ready

Loading your progress…

Poll a job until it is ready, with a deadline — Python practice · Runtime