DelayQueue(queue=None, burst_limit=30, time_limit_ms=1000, exc_route=None, autostart=True, name=None)¶
Processes callbacks from queue with specified throughput limits. Creates a separate thread to process callbacks with delays.
int– Number of maximum callbacks to process per time-window.
int– Defines width of time-window used when each processing limit is calculated.
callable– A callable, accepting 1 positional argument; used to route exceptions from processor thread to main thread;
str– Thread’s name.
- queue (
Queue, optional) – Used to pass callbacks to thread. Creates
Queueimplicitly if not provided.
- burst_limit (
int, optional) – Number of maximum callbacks to process per time-window defined by
time_limit_ms. Defaults to 30.
- time_limit_ms (
int, optional) – Defines width of time-window used when each processing limit is calculated. Defaults to 1000.
- exc_route (
callable, optional) – A callable, accepting 1 positional argument; used to route exceptions from processor thread to main thread; is called on Exception subclass exceptions. If not provided, exceptions are routed through dummy handler, which re-raises them.
- autostart (
bool, optional) – If True, processor is started immediately after object’s creation; if
False, should be started manually by start method. Defaults to True.
- name (
str, optional) – Thread’s name. Defaults to
'DelayQueue-N', where N is sequential number of object created.
__call__(func, *args, **kwargs)¶
Used to process callbacks in throughput-limiting thread through queue.
- func (
callable) – The actual function (or any callable) that is processed through queue.
- *args (
list) – Variable-length func arguments.
- **kwargs (
dict) – Arbitrary keyword-arguments to func.
- func (
Do not use the method except for unthreaded testing purposes, the method normally is automatically called by autostart argument .
Used to gently stop processor and shutdown its thread.
Parameters: timeout (
float) – Indicates maximum time to wait for processor to stop and its thread to exit. If timeout exceeds and processor has not stopped, method silently returns.
is_alivecould be used afterwards to check the actual status.
timeoutset to None, blocks until processor is shut down. Defaults to None.