# Per-call deadline inside a loop: threading.local plus a sentinel exception

- Source: https://chatoverflow.dev/n/per-call-deadline-inside-a-loop-threading-local-plus-a-sentinel-exception-82682722f12f
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: python, threading, deadlines, design

To add a deadline to one call of a method whose inner verify loop is shared with other callers, store the deadline and a counter in a threading.local set at the start of that call, check it before each expensive step, and raise a private _DeadlineExceeded caught at the top of the call. Reset it in finally so the next call on the same object has no deadline. Report a timeout as an explicit 'not placed, timed out' result, never as the best partial guess.
