telegram.ext.MessageQueue¶
-
class
telegram.ext.
MessageQueue
(all_burst_limit=30, all_time_limit_ms=1000, group_burst_limit=20, group_time_limit_ms=60000, exc_route=None, autostart=True)¶ Bases:
object
Implements callback processing with proper delays to avoid hitting Telegram’s message limits. Contains two
DelayQueue
, for group and for all messages, interconnected in delay chain. Callables are processed through groupDelayQueue
, then through allDelayQueue
for group-type messages. For non-group messages, only the allDelayQueue
is used.Deprecated since version 13.3:
telegram.ext.MessageQueue
in its current form is deprecated and will be reinvented in a future release. See this thread for a list of known bugs.- Parameters
all_burst_limit (
int
, optional) – Number of maximum all-type callbacks to process per time-window defined byall_time_limit_ms
. Defaults to 30.all_time_limit_ms (
int
, optional) – Defines width of all-type time-window used when each processing limit is calculated. Defaults to 1000 ms.group_burst_limit (
int
, optional) – Number of maximum group-type callbacks to process per time-window defined bygroup_time_limit_ms
. Defaults to 20.group_time_limit_ms (
int
, optional) – Defines width of group-type time-window used when each processing limit is calculated. Defaults to 60000 ms.exc_route (
callable
, optional) – A callable, accepting one positional argument; used to route exceptions from processor threads to main thread; is called onException
subclass exceptions. If not provided, exceptions are routed through dummy handler, which re-raises them.autostart (
bool
, optional) – IfTrue
, processors are started immediately after object’s creation; ifFalse
, should be started manually bystart
method. Defaults toTrue
.
-
__call__
(promise, is_group_msg=False)¶ Processes callables in throughput-limiting queues to avoid hitting limits (specified with
burst_limit
andtime_limit
.- Parameters
promise (
callable
) – Mainly thetelegram.utils.promise.Promise
(see Notes for other callables), that is processed in delay queues.is_group_msg (
bool
, optional) – Defines whetherpromise
would be processed in group*+*all*DelayQueue``s (if set to :obj:`True`), or only through *all* ``DelayQueue
(if set toFalse
), resulting in needed delays to avoid hitting specified limits. Defaults toFalse
.
Note
Method is designed to accept
telegram.utils.promise.Promise
aspromise
argument, but other callables could be used too. For example, lambdas or simple functions could be used to wrap original func to be called with needed args. In that case, be sure that either wrapper func does not raise outside exceptions or the properexc_route
handler is provided.- Returns
Used as
promise
argument.- Return type
callable
-
__init__
(all_burst_limit=30, all_time_limit_ms=1000, group_burst_limit=20, group_time_limit_ms=60000, exc_route=None, autostart=True)¶ Initialize self. See help(type(self)) for accurate signature.
-
__weakref__
¶ list of weak references to the object (if defined)
-
start
()¶ Method is used to manually start the
MessageQueue
processing.
-
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 toNone
, blocks until processor is shut down. Defaults toNone
.