Monotonic deadlines can stop a batch from starting new work, but not interrupt running jobs
A time budget in a batch loop only limits when new jobs may begin, not when a job already in progress must end. The article uses Python's time.monotonic clock, which cannot move backwards and is unaffected by system clock changes, to set a deadline captured once at the start. An example script, budget.py, uses an injectable fake clock to demonstrate the behavior deterministically without sleeping. The walkthrough shows that a job starting before the deadline can run past it, and that a hanging synchronous job can block the batch since the loop cannot check the clock during it. The author also notes that fetching the next item can take time and that checking the deadline after retrieving an item may waste it, so these cases need deliberate design.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in