telegram.ext.DelayQueue¶
-
class
telegram.ext.DelayQueue(queue=None, burst_limit=30, time_limit_ms=1000, exc_route=None, autostart=True, name=None)¶ Bases:
threading.ThreadProcesses callbacks from queue with specified throughput limits. Creates a separate thread to process callbacks with delays.
-
burst_limit¶ int– Number of maximum callbacks to process per time-window.
-
time_limit¶ int– Defines width of time-window used when each processing limit is calculated.
-
exc_route¶ callable– A callable, accepting 1 positional argument; used to route exceptions from processor thread to main thread;
-
name¶ str– Thread’s name.
Parameters: - queue (
Queue, optional) – Used to pass callbacks to thread. CreatesQueueimplicitly if not provided. - burst_limit (
int, optional) – Number of maximum callbacks to process per time-window defined bytime_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; ifFalse, 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.
Parameters: - 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 (
-
run()¶ Do not use the method except for unthreaded testing purposes, the method normally is automatically called by autostart argument.
-
stop(timeout=None)¶ 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.
-