dramatiq API Reference
Fast and reliable background task processing library for Python 3.
dramatiq.Actor
Python Library Documentation: class Actor in module dramatiq.actor class Actor(typing.Generic) | Actor(fn: 'Union[Callable[P, Awaitable[R]], Callable[P, R]]', *, broker: 'Broker', actor_name: 'str', queue_name: 'str', priority: 'int', options: 'dict[str, Any]') -> 'None' | | Thin wrapper around callables that stores metadata about how | they should be executed asynchronously. Actors are callable. | | Attributes: | logger(Logger): The actor's logger. | fn(callable): The underlying callable. | broker(Broker): The broker this actor is bound to. | actor_name(str): The actor's name. | queue_name(str): The actor's queue. | priority(int): The actor's priority. | options(dict): Arbitrary options that are passed to the broker | and middleware. | | Method resolution order: | Actor | typing.Generic | builtins.object | | Methods defined here: | | __call__(self, *args: 'P.args', **kwargs: 'P.kwargs') -> 'R' | Synchronously call this actor. | | Parameters: | *args: Positional arguments to send to the actor. | **kwargs: Keyword arguments to send to the actor. | | Returns: | Whatever the underlying function backing this actor returns. | | __init__(self, fn: 'Union[Callable[P, Awaitable[R]], Callable[P, R]]', *, broker: 'Broker', actor_name: 'str', queue_name: 'str', priority: 'int', options: 'dict[str, Any]') -> 'None' | Initialize self. See help(type(self)) for accurate signature. | | __repr__(self) -> 'str' | Return repr(self). | | __str__(self) -> 'str' | Return str(self). | | message(self, *args: 'P.args', **kwargs: 'P.kwargs') -> 'Message[R]' | Build a message. This method is useful if you want to | compose actors. See the actor composition documentation for | details. | | Parameters: | *args(tuple): Positional arguments to send to the actor. | **kwargs: Keyword arguments to send to the actor. | | Examples: | >>> (add.message(1, 2) | add.message(3)) | pipeline([add(1, 2), add(3)]) | | Returns: | Message: A message that can be enqueued on a broker. | | message_with_options(self, *, args: 'tuple' = (), kwargs: 'Optional[dict[str, Any]]' = None, **options) -> 'Message[R]' | Build a message with an arbitrary set of processing options. | This method is useful if you want to compose actors. See the | actor composition documentation for details. | | Parameters: | args(tuple): Positional arguments that are passed to the actor. | kwargs(dict): Keyword arguments that are passed to the actor. | **options: Arbitrary options that are passed to the | broker and any registered middleware. | | Returns: | Message: A message that can be enqueued on a broker. | | send(self, *args: 'P.args', **kwargs: 'P.kwargs') -> 'Message[R]' | Asynchronously send a message to this actor. | | Parameters: | *args: Positional arguments to send to the actor. | **kwargs: Keyword arguments to send to the actor. | | Returns: | Message: The enqueued message. | | send_with_options(self, *, args: 'tuple' = (), kwargs: 'Optional[dict[str, Any]]' = None, delay: 'Optional[timedelta | int]' = None, **options) -> 'Message[R]' | Asynchronously send a message to this actor, along with an | arbitrary set of processing options for the broker and | middleware. | | Parameters: | args(tuple): Positional arguments that are passed to the actor. | kwargs(dict): Keyword arguments that are passed to the actor. | delay(int): The minimum amount of time, in milliseconds, the | message should be delayed by. Also accepts a timedelta. | **options: Arbitrary options that are passed to the | broker and any registered middleware. | | Returns: | Message: The enqueued message. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __orig_bases__ = (typing.Generic[~P, ~R],) | | __parameters__ = (~P, ~R) | | ---------------------------------------------------------------------- | Class methods inherited from typing.Generic: | | __class_getitem__(...) | Parameterizes a generic class. | | At least, parameterizing a generic class is the *main* thing this | method does. For example, for some generic class `Foo`, this is called | when we do `Foo[int]` - there, with `cls=Foo` and `params=int`. | | However, note that this method is also called when defining generic | classes in the first place with `class Foo[T]: ...`. | | __init_subclass__(...) | Function to initialize subclasses.
dramatiq.ActorNotFound
Python Library Documentation: class ActorNotFound in module dramatiq.errors class ActorNotFound(BrokerError) | ActorNotFound(message) | | Raised when a message is sent to an actor that hasn't been declared. | | Method resolution order: | ActorNotFound | BrokerError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.Broker
Python Library Documentation: class Broker in module dramatiq.broker class Broker(builtins.object) | Broker(middleware: 'Optional[list[Middleware]]' = None) -> 'None' | | Base class for broker implementations. | | Parameters: | middleware(list[Middleware]): The set of middleware that apply | to this broker. If you supply this parameter, you are | expected to declare *all* middleware. Most of the time, | you'll want to use :meth:`.add_middleware` instead. | See :ref:`customizing-middleware` for details. | | Attributes: | actor_options(set[str]): The names of all the options actors may | overwrite when they are declared. | | Methods defined here: | | __init__(self, middleware: 'Optional[list[Middleware]]' = None) -> 'None' | Initialize self. See help(type(self)) for accurate signature. | | add_middleware(self, middleware: 'Middleware', *, before: 'Optional[type[Middleware]]' = None, after: 'Optional[type[Middleware]]' = None) -> 'None' | Add a middleware object to this broker. The middleware is | appended to the end of the middleware list by default. | | You can specify another middleware (by class) as a reference | point for where the new middleware should be added. | | Duplicates of middleware are allowed. | If there's already a middleware object of the same class | added to the broker, the middleware will be added | for the second time. | | Parameters: | middleware(Middleware): The middleware. | before(type): Add this middleware before a specific one. | after(type): Add this middleware after a specific one. | | Raises: | ValueError: When either ``before`` or ``after`` refer to a | middleware that hasn't been registered yet. | | close(self) -> 'None' | Close this broker and perform any necessary cleanup actions. | | consume(self, queue_name: 'str', prefetch: 'int' = 1, timeout: 'int' = 30000) -> 'Consumer' | Get an iterator that consumes messages off of the queue. | | Raises: | QueueNotFound: If the given queue was never declared. | | Parameters: | queue_name(str): The name of the queue to consume messages off of. | prefetch(int): The number of messages to prefetch per consumer. | timeout(int): The amount of time in milliseconds to idle for. | | Returns: | Consumer: A message iterator. | | declare_actor(self, actor: 'Actor') -> 'None' | Declare a new actor on this broker. Declaring an Actor | twice replaces the first actor with the second by name. | | Parameters: | actor(Actor): The actor being declared. | | declare_queue(self, queue_name: 'str') -> 'None' | Declare a queue on this broker. This method must be | idempotent. | | Parameters: | queue_name(str): The name of the queue being declared. | | emit_after(self, signal: 'str', *args: 'Any', **kwargs: 'Any') -> 'None' | | emit_before(self, signal: 'str', *args: 'Any', **kwargs: 'Any') -> 'None' | | enqueue(self, message: 'Message', *, delay: 'Optional[int]' = None) -> 'Message' | Enqueue a message on this broker. | | Parameters: | message(Message): The message to enqueue. | delay(int): The number of milliseconds to delay the message for. | | Returns: | Message: Either the original message or a copy of it. | | flush(self, queue_name: 'str') -> 'None' | Drop all the messages from a queue. | | Parameters: | queue_name(str): The name of the queue to flush. | | flush_all(self) -> 'None' | Drop all messages from all declared queues. | | get_actor(self, actor_name: 'str') -> 'Actor' | Look up an actor by its name. | | Parameters: | actor_name(str): The name to look up. | | Raises: | ActorNotFound: If the actor was never declared. | | Returns: | Actor: The actor. | | get_declared_actors(self) -> 'set[str]' | Get all declared actors. | | Returns: | set[str]: The names of all the actors declared so far on | this Broker. | | get_declared_delay_queues(self) -> 'set[str]' | Get all declared delay queues. | | Returns: | set[str]: The names of all the delay queues declared so far | on this Broker. | | get_declared_queues(self) -> 'set[str]' | Get all declared queues. | | Returns: | set[str]: The names of all the queues declared so far on | this Broker. | | get_results_backend(self) -> 'ResultBackend' | Get the backend of the Results middleware. | | Raises: | RuntimeError: If the broker doesn't have a results backend. | | Returns: | ResultBackend: The backend. | | join(self, queue_name: 'str', *, timeout: 'Optional[int]' = None) -> 'None' | Wait for all the messages on the given queue to be | processed. This method is only meant to be used in tests to | wait for all the messages in a queue to be processed. | | Subclasses that implement this function may add parameters. | | Parameters: | queue_name(str): The queue to wait on. | timeout(Optional[int]): The max amount of time, in | milliseconds, to wait on this queue. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.BrokerConnectionError
Python Library Documentation: class BrokerConnectionError in module dramatiq.errors class BrokerConnectionError(BrokerError) | BrokerConnectionError(message) | | Base class for broker connection-related errors. | | Method resolution order: | BrokerConnectionError | BrokerError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.BrokerError
Python Library Documentation: class BrokerError in module dramatiq.errors class BrokerError(DramatiqError) | BrokerError(message) | | Base class for broker-related errors. | | Method resolution order: | BrokerError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.ConnectionClosed
Python Library Documentation: class ConnectionClosed in module dramatiq.errors class ConnectionClosed(BrokerConnectionError) | ConnectionClosed(message) | | Raised when a broker connection is suddenly closed. | | Method resolution order: | ConnectionClosed | BrokerConnectionError | BrokerError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.ConnectionFailed
Python Library Documentation: class ConnectionFailed in module dramatiq.errors class ConnectionFailed(BrokerConnectionError) | ConnectionFailed(message) | | Raised when a broker connection could not be opened. | | Method resolution order: | ConnectionFailed | BrokerConnectionError | BrokerError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.Consumer
Python Library Documentation: class Consumer in module dramatiq.broker class Consumer(builtins.object) | Consumers iterate over messages on a queue. | | Consumers and their MessageProxies are *not* thread-safe. | | Methods defined here: | | __iter__(self) -> 'Self' | Returns this instance as a Message iterator. | | __next__(self) -> 'MessageProxy | None' | Retrieve the next message off of the queue. | | This method should block for a limited amount of time | (typically self.timeout) until a message becomes available. | After that time is elapsed, return None if no message is available. | | Returns: | MessageProxy: A transparent proxy around a Message that can | be used to acknowledge or reject it once it's done being | processed. | None: When no message was available. | | ack(self, message: 'MessageProxy') -> 'None' | Acknowledge that a message has been processed, removing it | from the broker. | | Parameters: | message(MessageProxy): The message to acknowledge. | | close(self) -> 'None' | Close this consumer and perform any necessary cleanup actions. | | nack(self, message: 'MessageProxy') -> 'None' | Move a message to the dead-letter queue. | | Parameters: | message(MessageProxy): The message to reject. | | requeue(self, messages: 'Iterable[MessageProxy]') -> 'None' | Move unacked messages back to their queues. This is called | by consumer threads when they fail or are shut down. The | default implementation does nothing. | | Parameters: | messages(Iterable[MessageProxy]): The messages to requeue. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.ConsumerThread
Python Library Documentation: class ConsumerThread in module dramatiq.worker
class ConsumerThread(threading.Thread)
| ConsumerThread(*, broker: 'Broker', queue_name: 'str', prefetch: 'int', work_queue: 'PriorityQueue[_WorkQueueItem]', worker_timeout: 'int') -> 'None'
|
| Method resolution order:
| ConsumerThread
| threading.Thread
| builtins.object
|
| Methods defined here:
|
| __init__(self, *, broker: 'Broker', queue_name: 'str', prefetch: 'int', work_queue: 'PriorityQueue[_WorkQueueItem]', worker_timeout: 'int') -> '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 a list or tuple of arguments 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.
|
| close(self) -> 'None'
| Close this consumer thread and its underlying connection.
|
| handle_delayed_messages(self) -> 'None'
| Enqueue any delayed messages whose eta has passed.
|
| handle_message(self, message: 'MessageProxy') -> 'None'
| Handle a message received off of the underlying consumer.
| If the message has an eta, delay it. Otherwise, put it on the
| work queue.
|
| pause(self) -> 'None'
| Pause this consumer.
|
| post_process_message(self, message: 'MessageProxy') -> 'None'
| Called by worker threads whenever they're done processing
| individual messages, signaling that each message is ready to
| be acked or rejected.
|
| requeue_messages(self, messages: 'Iterable[MessageProxy]') -> 'None'
| Called on worker shutdown and whenever there is a
| connection error to move unacked messages back to their
| respective queues asap.
|
| resume(self) -> 'None'
| Resume this consumer.
|
| run(self) -> 'None'
| Method representing the thread's activity.
|
| You may override this method in a subclass. The standard run() method
| invokes the callable object passed to the object's constructor as the
| target argument, if any, with sequential and keyword arguments taken
| from the args and kwargs arguments, respectively.
|
| stop(self) -> 'None'
| Initiate the ConsumerThread shutdown sequence.
|
| Code calling this method should then join on the thread and
| wait for it to finish shutting down.
|
| ----------------------------------------------------------------------
| Methods inherited from threading.Thread:
|
| __repr__(self)
| Return repr(self).
|
| getName(self)
| Return a string used for identification purposes only.
|
| This method is deprecated, use the name attribute instead.
|
| isDaemon(self)
| Return whether this thread is a daemon.
|
| This method is deprecated, use the daemon attribute instead.
|
| is_alive(self)
| Return whether the thread is alive.
|
| This method returns True just before the run() method starts until just
| after the run() method terminates. See also the module function
| enumerate().
|
| join(self, timeout=None)
| Wait until the thread terminates.
|
| This blocks the calling thread until the thread whose join() method is
| called terminates -- either normally or through an unhandled exception
| or until the optional timeout occurs.
|
| When the timeout argument is present and not None, it should be a
| floating-point number specifying a timeout for the operation in seconds
| (or fractions thereof). As join() always returns None, you must call
| is_alive() after join() to decide whether a timeout happened -- if the
| thread is still alive, the join() call timed out.
|
| When the timeout argument is not present or None, the operation will
| block until the thread terminates.
|
| A thread can be join()ed many times.
|
| join() raises a RuntimeError if an attempt is made to join the current
| thread as that would cause a deadlock. It is also an error to join() a
| thread before it has been started and attempts to do so raises the same
| exception.
|
| setDaemon(self, daemonic)
| Set whether this thread is a daemon.
|
| This method is deprecated, use the .daemon property instead.
|
| setName(self, name)
| Set the name string for this thread.
|
| This method is deprecated, use the name attribute instead.
|
| start(self)
| Start the thread's activity.
|
| It must be called at most once per thread object. It arranges for the
| object's run() method to be invoked in a separate thread of control.
|
| This method will raise a RuntimeError if called more than once on the
| same thread object.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from threading.Thread:
|
| ident
| Thread identifier of this thread or None if it has not been started.
|
| This is a nonzero integer. See the get_ident() function. Thread
| identifiers may be recycled when a thread exits and another thread is
| created. The identifier is available even after the thread has exited.
|
| native_id
| Native integral thread ID of this thread, or None if it has not been started.
|
| This is a non-negative integer. See the get_native_id() function.
| This represents the Thread ID as reported by the kernel.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from threading.Thread:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| daemon
| A boolean value indicating whether this thread is a daemon thread.
|
| This must be set before start() is called, otherwise RuntimeError is
| raised. Its initial value is inherited from the creating thread; the
| main thread is not a daemon thread and therefore all threads created in
| the main thread default to daemon = False.
|
| The entire Python program exits when only daemon threads are left.
|
| name
| A string used for identification purposes only.
|
| It has no semantics. Multiple threads may be given the same name. The
| initial name is set by the constructor.
dramatiq.DecodeError
Python Library Documentation: class DecodeError in module dramatiq.errors class DecodeError(DramatiqError) | DecodeError(message, data, error) | | Raised when a message fails to decode. | | Method resolution order: | DecodeError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods defined here: | | __init__(self, message, data, error) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from DramatiqError: | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.DramatiqError
Python Library Documentation: class DramatiqError in module dramatiq.errors class DramatiqError(builtins.Exception) | DramatiqError(message) | | Base class for all dramatiq errors. | | Method resolution order: | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods defined here: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.Encoder
Python Library Documentation: class Encoder in module dramatiq.encoder
class Encoder(abc.ABC)
| Base class for message encoders.
|
| Method resolution order:
| Encoder
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| decode(self, data: 'bytes') -> 'MessageData'
| Convert a bytestring into message metadata.
|
| encode(self, data: 'MessageData') -> 'bytes'
| Convert message metadata into a bytestring.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'decode', 'encode'})
dramatiq.GenericActor
Python Library Documentation: class GenericActor in module dramatiq.generic
class GenericActor(builtins.object)
| Base-class for class-based actors.
|
| Each subclass may define an inner class named ``Meta``. You can
| use the meta class to provide broker options for the actor.
|
| Classes that have ``abstract = True`` in their meta class are
| considered abstract base classes and are not converted into
| actors. You can't send these classes messages, you can only
| inherit from them. Actors that subclass abstract base classes
| inherit their parents' meta classes.
|
| Example:
|
| >>> class BaseTask(GenericActor):
| ... class Meta:
| ... abstract = True
| ... queue_name = "tasks"
| ... max_retries = 20
| ...
| ... def get_task_name(self):
| ... raise NotImplementedError
| ...
| ... def perform(self):
| ... print(f"Hello from {self.get_task_name()}!")
|
| >>> class FooTask(BaseTask):
| ... def get_task_name(self):
| ... return "Foo"
|
| >>> class BarTask(BaseTask):
| ... def get_task_name(self):
| ... return "Bar"
|
| >>> FooTask.send()
| >>> BarTask.send()
|
| Attributes:
| logger(Logger): The actor's logger.
| broker(Broker): The broker this actor is bound to.
| actor_name(str): The actor's name.
| queue_name(str): The actor's queue.
| priority(int): The actor's priority.
| options(dict): Arbitrary options that are passed to the broker
| and middleware.
|
| Methods defined here:
|
| __call__(self, *args, **kwargs)
| Call self as a function.
|
| perform(self, *args, **kwargs)
| This is the method that gets called when the actor receives
| a message. All non-abstract subclasses must implement this
| method.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| Meta = <class 'dramatiq.generic.GenericActor.Meta'>
dramatiq.JSONEncoder
Python Library Documentation: class JSONEncoder in module dramatiq.encoder class JSONEncoder(Encoder) | Encodes messages as JSON. This is the default encoder. | | Method resolution order: | JSONEncoder | Encoder | abc.ABC | builtins.object | | Methods defined here: | | decode(self, data: 'bytes') -> 'MessageData' | Convert a bytestring into message metadata. | | encode(self, data: 'MessageData') -> 'bytes' | Convert message metadata into a bytestring. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Data descriptors inherited from Encoder: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.Message
Python Library Documentation: class Message in module dramatiq.message
class Message(typing.Generic)
| Message(queue_name: 'str', actor_name: 'str', args: 'tuple[Any, ...]', kwargs: 'dict[str, Any]', options: 'dict[str, Any]', message_id: 'str' = <factory>, message_timestamp: 'int' = <factory>) -> None
|
| Encapsulates metadata about messages being sent to individual actors.
|
| Parameters:
| queue_name(str): The name of the queue the message belongs to.
| actor_name(str): The name of the actor that will receive the message.
| args(tuple): Positional arguments that are passed to the actor.
| kwargs(dict): Keyword arguments that are passed to the actor.
| options(dict): Arbitrary options passed to the broker and middleware.
| message_id(str): A globally-unique id assigned to the actor.
| message_timestamp(int): The UNIX timestamp in milliseconds
| representing when the message was first enqueued.
|
| Method resolution order:
| Message
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __delattr__(self, name)
| Implement delattr(self, name).
|
| __eq__(self, other)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, queue_name: 'str', actor_name: 'str', args: 'tuple[Any, ...]', kwargs: 'dict[str, Any]', options: 'dict[str, Any]', message_id: 'str' = <factory>, message_timestamp: 'int' = <factory>) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __lt__(self, other: 'Message') -> 'bool'
| Return self<value.
|
| __or__(self, other) -> 'pipeline'
| Combine this message into a pipeline with "other".
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| __setattr__(self, name, value)
| Implement setattr(self, name, value).
|
| __str__(self) -> 'str'
| Return str(self).
|
| _asdict = asdict(self) -> 'dict[str, Any]'
|
| _replace(self, **changes) -> 'Message[R]'
|
| asdict(self) -> 'dict[str, Any]'
| Convert this message to a dictionary.
|
| copy(self, **attributes) -> 'Message'
| Create a copy of this message.
|
| encode(self) -> 'bytes'
| Convert this message to a bytestring.
|
| get_result(self, *, backend: 'Optional[ResultBackend]' = None, block: 'bool' = False, timeout: 'Optional[int]' = None) -> 'R'
| Get the result associated with this message from a result
| backend.
|
| Warning:
| If you use multiple result backends or brokers you should
| always pass the backend parameter. This method is only able
| to infer the result backend off of the default broker.
|
| Parameters:
| backend(ResultBackend): The result backend to use to get the
| result. If omitted, this method will try to find and use
| the result backend on the default broker instance.
| block(bool): Whether or not to block while waiting for a
| result.
| timeout(int): The maximum amount of time, in ms, to block
| while waiting for a result. Defaults to 10 seconds.
|
| Raises:
| RuntimeError: If there is no result backend on the default
| broker.
| ResultMissing: When block is False and the result isn't set.
| ResultTimeout: When waiting for a result times out.
|
| Returns:
| object: The result.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| decode(data: 'bytes') -> 'Message'
| Convert a bytestring to a message.
|
| Raises:
| DecodeError: When the decoder raises an exception while
| decoding `data`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| _field_defaults
|
| _fields
|
| message_datetime
| Read ``message_timestamp`` as a UTC-aware datetime.
|
| Datetime precision is limited by the representation of ``Message.message_timestamp``, which is an
| integer storing milliseconds.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'actor_name': 'str', 'args': 'tuple[Any, ...]', 'kw...
|
| __dataclass_fields__ = {'actor_name': Field(name='actor_name',type='st...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __match_args__ = ('queue_name', 'actor_name', 'args', 'kwargs', 'optio...
|
| __orig_bases__ = (typing.Generic[+R],)
|
| __parameters__ = (+R,)
|
| ----------------------------------------------------------------------
| Class methods inherited from typing.Generic:
|
| __class_getitem__(...)
| Parameterizes a generic class.
|
| At least, parameterizing a generic class is the *main* thing this
| method does. For example, for some generic class `Foo`, this is called
| when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
|
| However, note that this method is also called when defining generic
| classes in the first place with `class Foo[T]: ...`.
|
| __init_subclass__(...)
| Function to initialize subclasses.
dramatiq.MessageProxy
Python Library Documentation: class MessageProxy in module dramatiq.broker
class MessageProxy(builtins.object)
| MessageProxy(message: 'Message') -> 'None'
|
| Base class for messages returned by :meth:`Broker.consume`.
|
| Methods defined here:
|
| __eq__(self, other) -> 'bool'
| Return self==value.
|
| __getattr__(self, name: 'str') -> 'Any'
|
| __init__(self, message: 'Message') -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| __lt__(self, other) -> 'bool'
| Return self<value.
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| __str__(self) -> 'str'
| Return str(self).
|
| clear_exception(self) -> 'None'
| Remove the exception from this message.
|
| fail(self) -> 'None'
| Mark this message for rejection.
|
| stuff_exception(self, exception: 'BaseException') -> 'None'
| Stuff an exception into this message.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
dramatiq.Middleware
Python Library Documentation: class Middleware in module dramatiq.middleware.middleware class Middleware(builtins.object) | Base class for broker middleware. The default implementations | for all hooks are no-ops and subclasses may implement whatever | subset of hooks they like. | | Methods defined here: | | after_ack(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called after a message has been acknowledged. | | after_consumer_thread_boot(self, broker: 'Broker', thread: 'ConsumerThread') -> 'None' | Called from a consumer thread after it starts but before it starts its run loop. | | after_declare_actor(self, broker: 'Broker', actor: 'Actor') -> 'None' | Called after an actor has been declared. | | after_declare_delay_queue(self, broker: 'Broker', queue_name: 'str') -> 'None' | Called after a delay queue has been declared. | | after_declare_queue(self, broker: 'Broker', queue_name: 'str') -> 'None' | Called after a queue has been declared. | | This signals that the queue has been registered with the | broker, but it does not necessarily mean that it was created | on the server yet. For example, the RabbitMQ broker declares | queues when actors are created, but it doesn't instantiate | them until messages are enqueued or consumed. | | after_enqueue(self, broker: 'Broker', message: 'Message', delay: 'int') -> 'None' | Called after a message has been enqueued (including retries). | | after_nack(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called after a message has been rejected. | | after_process_boot(self, broker: 'Broker') -> 'None' | Called immediately after subprocess start up. | | after_process_message(self, broker: 'Broker', message: 'MessageProxy', *, result: 'Optional[Any]' = None, exception: 'Optional[BaseException]' = None) -> 'None' | Called after a message has been processed. | | after_skip_message(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called instead of ``after_process_message`` after a message | has been skipped. | | after_worker_boot(self, broker: 'Broker', worker: 'Worker') -> 'None' | Called after the worker process has started up. | | after_worker_shutdown(self, broker: 'Broker', worker: 'Worker') -> 'None' | Called after the worker process shuts down. | | after_worker_thread_boot(self, broker: 'Broker', thread: 'WorkerThread') -> 'None' | Called from a worker thread after it starts but before it starts its run loop. | | before_ack(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called before a message is acknowledged. | | before_consumer_thread_shutdown(self, broker: 'Broker', thread: 'ConsumerThread') -> 'None' | Called before a consumer thread shuts down. This may be | used to clean up thread-local resources (such as Django | database connections). | | before_declare_actor(self, broker: 'Broker', actor: 'Actor') -> 'None' | Called before an actor is declared. | | before_declare_queue(self, broker: 'Broker', queue_name: 'str') -> 'None' | Called before a queue is declared. | | before_delay_message(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called before a message has been delayed in worker memory. | | before_enqueue(self, broker: 'Broker', message: 'Message', delay: 'int') -> 'None' | Called before a message is enqueued (including retries). | | before_nack(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called before a message is rejected. | | before_process_message(self, broker: 'Broker', message: 'MessageProxy') -> 'None' | Called before a message is processed. | | Raises: | SkipMessage: If the current message should be skipped. When | this is raised, ``after_skip_message`` is emitted instead | of ``after_process_message``. | | before_worker_boot(self, broker: 'Broker', worker: 'Worker') -> 'None' | Called before the worker process starts up. | | before_worker_shutdown(self, broker: 'Broker', worker: 'Worker') -> 'None' | Called before the worker process shuts down. | | before_worker_thread_shutdown(self, broker: 'Broker', thread: 'WorkerThread') -> 'None' | Called before a worker thread shuts down. This may be used | to clean up thread-local resources (such as Django database | connections). | | ---------------------------------------------------------------------- | Readonly properties defined here: | | actor_options | The set of options that may be configured on each actor. | | forks | A list of functions to run in separate forks of the main | process. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.PickleEncoder
Python Library Documentation: class PickleEncoder in module dramatiq.encoder class PickleEncoder(Encoder) | Pickles messages. | | Warning: | This encoder is not secure against maliciously-constructed data. | Use it at your own risk. | | Method resolution order: | PickleEncoder | Encoder | abc.ABC | builtins.object | | Methods defined here: | | decode(self, data: 'bytes') -> 'MessageData' | Convert a bytestring into message metadata. | | encode(self, data: 'MessageData') -> 'bytes' | Convert message metadata into a bytestring. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | ---------------------------------------------------------------------- | Data descriptors inherited from Encoder: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.QueueJoinTimeout
Python Library Documentation: class QueueJoinTimeout in module dramatiq.errors class QueueJoinTimeout(DramatiqError) | QueueJoinTimeout(message) | | Raised by brokers that support joining on queues when the join | operation times out. | | Method resolution order: | QueueJoinTimeout | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.QueueNotFound
Python Library Documentation: class QueueNotFound in module dramatiq.errors class QueueNotFound(BrokerError) | QueueNotFound(message) | | Raised when a message is sent to an queue that hasn't been declared. | | Method resolution order: | QueueNotFound | BrokerError | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.RateLimitExceeded
Python Library Documentation: class RateLimitExceeded in module dramatiq.errors class RateLimitExceeded(DramatiqError) | RateLimitExceeded(message) | | Raised when a rate limit has been exceeded. | | Method resolution order: | RateLimitExceeded | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from DramatiqError: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.Retry
Python Library Documentation: class Retry in module dramatiq.errors class Retry(DramatiqError) | Retry(message: 'str' = '', delay: 'Optional[int]' = None) | | Actors may raise this error when they should be retried. This | behaves just like any other exception from the perspective of the | :class:`Retries<dramatiq.middleware.Retries>` middleware, the only | difference is it doesn't get logged as an error. | | If the ``delay`` argument is provided, then the message will be | retried after at least that amount of time (in milliseconds). | | Method resolution order: | Retry | DramatiqError | builtins.Exception | builtins.BaseException | builtins.object | | Methods defined here: | | __init__(self, message: 'str' = '', delay: 'Optional[int]' = None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from DramatiqError: | | __str__(self) -> 'str' | Return str(self). | | ---------------------------------------------------------------------- | Data descriptors inherited from DramatiqError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
dramatiq.Worker
Python Library Documentation: class Worker in module dramatiq.worker class Worker(builtins.object) | Worker(broker: 'Broker', *, queues: 'Optional[set[str]]' = None, worker_timeout: 'int' = 1000, worker_threads: 'int' = 8) -> 'None' | | Workers consume messages off of all declared queues and | distribute those messages to individual worker threads for | processing. Workers don't block the current thread so it's | up to the caller to keep it alive. | | Don't run more than one Worker per process. | | Parameters: | broker(Broker) | queues(set[str]): An optional subset of queues to listen on. By | default, if this is not provided, the worker will listen on | all declared queues. | worker_timeout(int): The number of milliseconds workers should | wake up after if the queue is idle. | worker_threads(int): The number of worker threads to spawn. | | Methods defined here: | | __init__(self, broker: 'Broker', *, queues: 'Optional[set[str]]' = None, worker_timeout: 'int' = 1000, worker_threads: 'int' = 8) -> 'None' | Initialize self. See help(type(self)) for accurate signature. | | join(self) -> 'None' | Wait for this worker to complete its work in progress. | This method is useful when testing code. | | pause(self) -> 'None' | Pauses all the worker threads. | | resume(self) -> 'None' | Resumes all the worker threads. | | start(self) -> 'None' | Initialize the worker boot sequence and start up all the | worker threads. | | stop(self, timeout: 'int' = 600000) -> 'None' | Gracefully stop the Worker and all of its consumers and | workers. | | Parameters: | timeout(int): The number of milliseconds to wait for | everything to shut down. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.WorkerThread
Python Library Documentation: class WorkerThread in module dramatiq.worker
class WorkerThread(threading.Thread)
| WorkerThread(*, broker: 'Broker', consumers: 'dict[str, ConsumerThread]', work_queue: 'PriorityQueue[_WorkQueueItem]', worker_timeout: 'int') -> 'None'
|
| WorkerThreads process incoming messages off of the work queue
| on a loop. By themselves, they don't do any sort of network IO.
|
| Parameters:
| broker(Broker)
| consumers(dict[str, ConsumerThread])
| work_queue(PriorityQueue[_WorkQueueItem])
| worker_timeout(int)
|
| Method resolution order:
| WorkerThread
| threading.Thread
| builtins.object
|
| Methods defined here:
|
| __init__(self, *, broker: 'Broker', consumers: 'dict[str, ConsumerThread]', work_queue: 'PriorityQueue[_WorkQueueItem]', worker_timeout: 'int') -> '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 a list or tuple of arguments 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.
|
| pause(self) -> 'None'
| Pause this worker.
|
| process_message(self, message: 'MessageProxy') -> 'None'
| Process a message pulled off of the work queue then push it
| back to its associated consumer for post processing. Stuff any SkipMessage
| exception or BaseException into the message [proxy] so that it may be used
| by the stub broker to provide a nicer testing experience. Also used by the
| results middleware to pass exceptions into results.
|
| Parameters:
| message(MessageProxy)
|
| resume(self) -> 'None'
| Resume this worker.
|
| run(self) -> 'None'
| Method representing the thread's activity.
|
| You may override this method in a subclass. The standard run() method
| invokes the callable object passed to the object's constructor as the
| target argument, if any, with sequential and keyword arguments taken
| from the args and kwargs arguments, respectively.
|
| stop(self) -> 'None'
| Initiate the WorkerThread shutdown process.
|
| Code calling this method should then join on the thread and
| wait for it to finish shutting down.
|
| ----------------------------------------------------------------------
| Methods inherited from threading.Thread:
|
| __repr__(self)
| Return repr(self).
|
| getName(self)
| Return a string used for identification purposes only.
|
| This method is deprecated, use the name attribute instead.
|
| isDaemon(self)
| Return whether this thread is a daemon.
|
| This method is deprecated, use the daemon attribute instead.
|
| is_alive(self)
| Return whether the thread is alive.
|
| This method returns True just before the run() method starts until just
| after the run() method terminates. See also the module function
| enumerate().
|
| join(self, timeout=None)
| Wait until the thread terminates.
|
| This blocks the calling thread until the thread whose join() method is
| called terminates -- either normally or through an unhandled exception
| or until the optional timeout occurs.
|
| When the timeout argument is present and not None, it should be a
| floating-point number specifying a timeout for the operation in seconds
| (or fractions thereof). As join() always returns None, you must call
| is_alive() after join() to decide whether a timeout happened -- if the
| thread is still alive, the join() call timed out.
|
| When the timeout argument is not present or None, the operation will
| block until the thread terminates.
|
| A thread can be join()ed many times.
|
| join() raises a RuntimeError if an attempt is made to join the current
| thread as that would cause a deadlock. It is also an error to join() a
| thread before it has been started and attempts to do so raises the same
| exception.
|
| setDaemon(self, daemonic)
| Set whether this thread is a daemon.
|
| This method is deprecated, use the .daemon property instead.
|
| setName(self, name)
| Set the name string for this thread.
|
| This method is deprecated, use the name attribute instead.
|
| start(self)
| Start the thread's activity.
|
| It must be called at most once per thread object. It arranges for the
| object's run() method to be invoked in a separate thread of control.
|
| This method will raise a RuntimeError if called more than once on the
| same thread object.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from threading.Thread:
|
| ident
| Thread identifier of this thread or None if it has not been started.
|
| This is a nonzero integer. See the get_ident() function. Thread
| identifiers may be recycled when a thread exits and another thread is
| created. The identifier is available even after the thread has exited.
|
| native_id
| Native integral thread ID of this thread, or None if it has not been started.
|
| This is a non-negative integer. See the get_native_id() function.
| This represents the Thread ID as reported by the kernel.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from threading.Thread:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| daemon
| A boolean value indicating whether this thread is a daemon thread.
|
| This must be set before start() is called, otherwise RuntimeError is
| raised. Its initial value is inherited from the creating thread; the
| main thread is not a daemon thread and therefore all threads created in
| the main thread default to daemon = False.
|
| The entire Python program exits when only daemon threads are left.
|
| name
| A string used for identification purposes only.
|
| It has no semantics. Multiple threads may be given the same name. The
| initial name is set by the constructor.
dramatiq.actor
Python Library Documentation: function actor in module dramatiq.actor
actor(fn: 'Optional[Callable[P, Union[Awaitable[R], R]]]' = None, *, actor_class: 'Callable[..., Actor[P, R]]' = <class 'dramatiq.actor.Actor'>, actor_name: 'Optional[str]' = None, queue_name: 'str' = 'default', priority: 'int' = 0, broker: 'Optional[Broker]' = None, **options: 'Any') -> 'Union[Actor[P, R], Callable]'
Declare an actor.
Examples:
>>> import dramatiq
>>> @dramatiq.actor
... def add(x, y):
... print(x + y)
...
>>> add
Actor(<function add at 0x106c6d488>, queue_name='default', actor_name='add')
>>> add(1, 2)
3
>>> add.send(1, 2)
Message(
queue_name='default',
actor_name='add',
args=(1, 2), kwargs={}, options={},
message_id='e0d27b45-7900-41da-bb97-553b8a081206',
message_timestamp=1497862448685)
Parameters:
fn(callable): The function to wrap.
actor_class(type): Type created by the decorator. Defaults to
:class:`Actor` but can be any callable as long as it returns an
actor and takes the same arguments as the :class:`Actor` class.
actor_name(str): The name of the actor.
queue_name(str): The name of the queue to use.
priority(int): The actor's global priority. If two tasks have
been pulled on a worker concurrently and one has a higher
priority than the other then it will be processed first.
Lower numbers represent higher priorities.
broker(Broker): The broker to use with this actor.
**options: Arbitrary options that vary with the set of
middleware that you use. See ``get_broker().actor_options``.
Returns:
Actor: The decorated function.
dramatiq.annotations
Python Library Documentation: _Feature in module __future__ object class _Feature(builtins.object) | _Feature(optionalRelease, mandatoryRelease, compiler_flag) | | Methods defined here: | | __init__(self, optionalRelease, mandatoryRelease, compiler_flag) | Initialize self. See help(type(self)) for accurate signature. | | __repr__(self) | Return repr(self). | | getMandatoryRelease(self) | Return release in which this feature will become mandatory. | | This is a 5-tuple, of the same form as sys.version_info, or, if | the feature was dropped, or the release date is undetermined, is None. | | getOptionalRelease(self) | Return first release in which this feature was recognized. | | This is a 5-tuple, of the same form as sys.version_info. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.get_broker
Python Library Documentation: function get_broker in module dramatiq.broker
get_broker() -> 'Broker'
Get the global broker instance.
If no global broker is set, a RabbitMQ broker will be returned.
If the RabbitMQ dependencies are not installed, a Redis broker
will be returned.
Returns:
Broker: The default Broker.
dramatiq.get_encoder
Python Library Documentation: function get_encoder in module dramatiq.message
get_encoder() -> 'Encoder'
Get the global encoder object.
Returns:
Encoder
dramatiq.get_logger
Python Library Documentation: function get_logger in module dramatiq.logging get_logger(module, name=None)
dramatiq.group
Python Library Documentation: class group in module dramatiq.composition class group(builtins.object) | group(children, *, broker=None) | | Run a group of actors in parallel. | | Parameters: | children(Iterator[Message|group|pipeline]): A sequence of | messages, groups or pipelines. | broker(Broker): The broker to run the group on. Defaults to the | current global broker. | | Methods defined here: | | __init__(self, children, *, broker=None) | Initialize self. See help(type(self)) for accurate signature. | | __len__(self) | Returns the size of the group. | | __str__(self) | Return str(self). | | add_completion_callback(self, message) | Adds a completion callback to run once every job in this | group has completed. Each group may have multiple completion | callbacks. | | Warning: | This functionality is dependent upon the optional |GroupCallbacks| | middleware. If that's not set up correctly, then calling | run after adding a callback will raise a RuntimeError. | | Parameters: | message(Message) | | get_results(self, *, block=False, timeout=None) | Get the results of each job in the group. | | Parameters: | block(bool): Whether or not to block until the results are stored. | timeout(int): The maximum amount of time, in milliseconds, | to wait for results when block is True. Defaults to 10 | seconds. | | Raises: | ResultMissing: When block is False and the results aren't set. | ResultTimeout: When waiting for results times out. | | Returns: | A result generator. | | run(self, *, delay=None) | Run the actors in this group. | | Parameters: | delay(int): The minimum amount of time, in milliseconds, | each message in the group should be delayed by. | | Returns: | group: This same group. | | wait(self, *, timeout=None) | Block until all the jobs in the group have finished or | until the timeout expires. | | Parameters: | timeout(int): The maximum amount of time, in ms, to wait. | Defaults to 10 seconds. | | Raises: | ResultTimeout: When waiting times out. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | completed | Returns True when all the jobs in the group have been | completed. Actors that don't store results are not counted, | meaning this may be inaccurate if all or some of your actors | don't store results. | | Raises: | RuntimeError: If your broker doesn't have a result backend | set up. | | completed_count | Returns the total number of jobs that have been completed. | Actors that don't store results are not counted, meaning this | may be inaccurate if all or some of your actors don't store | results. | | Raises: | RuntimeError: If your broker doesn't have a result backend | set up. | | Returns: | int: The total number of results. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
dramatiq.pipeline
Python Library Documentation: class pipeline in module dramatiq.composition
class pipeline(builtins.object)
| pipeline(children: 'Iterable[Message | pipeline]', *, broker=None)
|
| Chain actors together, passing the result of one actor to the
| next one in line.
|
| Parameters:
| children(Iterable[Message|pipeline]): A sequence of messages or
| pipelines. Child pipelines are flattened into the resulting
| pipeline.
| broker(Broker): The broker to run the pipeline on. Defaults to
| the current global broker.
|
| Methods defined here:
|
| __init__(self, children: 'Iterable[Message | pipeline]', *, broker=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __len__(self)
| Returns the length of the pipeline.
|
| __or__(self, other)
| Returns a new pipeline with "other" added to the end.
|
| __str__(self)
| Return str(self).
|
| get_result(self, *, block=False, timeout=None)
| Get the result of this pipeline.
|
| Pipeline results are represented by the result of the last
| message in the chain.
|
| Parameters:
| block(bool): Whether or not to block until a result is set.
| timeout(int): The maximum amount of time, in ms, to wait for
| a result when block is True. Defaults to 10 seconds.
|
| Raises:
| ResultMissing: When block is False and the result isn't set.
| ResultTimeout: When waiting for a result times out.
|
| Returns:
| object: The result.
|
| get_results(self, *, block=False, timeout=None)
| Get the results of each job in the pipeline.
|
| Parameters:
| block(bool): Whether or not to block until a result is set.
| timeout(int): The maximum amount of time, in ms, to wait for
| a result when block is True. Defaults to 10 seconds.
|
| Raises:
| ResultMissing: When block is False and the result isn't set.
| ResultTimeout: When waiting for a result times out.
|
| Returns:
| A result generator.
|
| run(self, *, delay=None)
| Run this pipeline.
|
| Parameters:
| delay(int): The minimum amount of time, in milliseconds, the
| pipeline should be delayed by. If both pipeline's delay and
| first message's delay are provided, the bigger value will be
| used.
|
| Returns:
| pipeline: Itself.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| completed
| Returns True when all the jobs in the pipeline have been
| completed. This will always return False if the last actor in
| the pipeline doesn't store results.
|
| Raises:
| RuntimeError: If your broker doesn't have a result backend
| set up.
|
| completed_count
| Returns the total number of jobs that have been completed.
| Actors that don't store results are not counted, meaning this
| may be inaccurate if all or some of your actors don't store
| results.
|
| Raises:
| RuntimeError: If your broker doesn't have a result backend
| set up.
|
| Returns:
| int: The total number of results.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'messages': 'list[Message]'}
dramatiq.set_broker
Python Library Documentation: function set_broker in module dramatiq.broker
set_broker(broker: 'Broker') -> 'None'
Configure the global broker instance.
Parameters:
broker(Broker): The broker instance to use by default.
dramatiq.set_encoder
Python Library Documentation: function set_encoder in module dramatiq.message
set_encoder(encoder: 'Encoder') -> 'None'
Set the global encoder object.
Parameters:
encoder(Encoder): The encoder instance to use when serializing
messages.