timeout-sampler
Poll any function until it succeeds or times out, with fine-grained exception handling
Get Started →Getting Started
-
Getting Started with timeout-sampler
Install timeout-sampler, write your first polling loop, and understand the core iteration pattern in under two minutes
User Guides
-
Polling a Function with TimeoutSampler
Learn how to create a TimeoutSampler iterator, yield function results, and break on a success condition
-
Retrying Functions with the @retry Decorator
Wrap any function with the @retry decorator so it automatically polls until a truthy return value or timeout
-
Filtering and Handling Exceptions
Configure exceptions_dict to selectively ignore, match by message text, or re-raise exceptions during polling
-
Controlling Log Output
Toggle elapsed-time logging, function-call details, and argument visibility using print_log, print_func_log, and print_func_args
-
Tracking Elapsed Time with TimeoutWatch
Use the TimeoutWatch helper to measure remaining time in custom polling or orchestration workflows
Recipes
-
Common Polling Patterns
Copy-paste recipes for waiting on API readiness, retrying flaky operations, polling with partial functions, and combining exception filters
Reference
-
TimeoutSampler API
Complete constructor parameters, iteration behavior, exception handling methods, and return semantics for TimeoutSampler
-
@retry Decorator API
All parameters accepted by the retry decorator and how they map to TimeoutSampler options
-
TimeoutWatch API
Constructor and remaining_time() method reference for the TimeoutWatch time-tracking class
-
TimeoutExpiredError Reference
Attributes, string representation, and access to last_exp and elapsed_time on the TimeoutExpiredError exception
Internals
-
How Exception Matching Works
Understand the inheritance-aware exception matching algorithm, message filtering, and the three outcome categories when an exception is raised inside the polled function