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.Thread

Processes callbacks from queue with specified throughput limits. Creates a separate thread to process callbacks with delays.

burst_limit

Number of maximum callbacks to process per time-window.

Type:int
time_limit

Defines width of time-window used when each processing limit is calculated.

Type:int
exc_route

A callable, accepting 1 positional argument; used to route exceptions from processor thread to main thread;

Type:callable
name

Thread’s name.

Type:str
Parameters:
  • queue (Queue, optional) – Used to pass callbacks to thread. Creates Queue implicitly 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.

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.
__init__(queue=None, burst_limit=30, time_limit_ms=1000, exc_route=None, autostart=True, name=None)

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

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_alive could be used afterwards to check the actual status. timeout set to None, blocks until processor is shut down. Defaults to None.