Mules
from uwsgiconf.runtime.mules import Mule , Farm
first_mule = Mule ( 1 )
@first_mule . offload ()
def for_mule ( * args , ** kwargs ):
# This function will be offloaded to and handled by mule 1.
...
farm_two = Farm ( 'two' )
@farm_two . offload ()
def for_farm ( * args , ** kwargs ):
# And this one will be offloaded to farm `two` and handled by any mule from that farm.
...
Functions
mule_offload
mule_offload (
mule_or_farm : TypeMuleFarm = None , # (1)!
) -> Callable
If not set, offloads to a first mule.
Decorator. Use to offload function execution to a mule or a farm.
Classes
Farm
Farm ( name : str , mules : list [ int ] | None = None )
Represents uWSGI Mule Farm.
Note
Register farms before using this. E.g.:
section.workers.set_mules_params(farms=section.workers.mule_farm('myfarm', 2))
is_mine
Returns flag indicating whether the current mule belongs to this farm.
get_farms
. get_farms () -> list [ Farm ]
Returns a list of registered farm objects.
farms = Farm . get_farms ()
first_farm = farms [ 0 ]
first_farm_first_mule = first_farm . mules [ 0 ]
get_message
Reads a mule farm message.
ValueError If not in a mule
offload
Decorator. Allows to offload function execution on mules of this farm.
first_mule = Farm ( 'myfarm' )
@first_mule . offload ()
def for_mule ( * args , ** kwargs ):
# This function will be offloaded to farm `myfarm` and handled by any mule from that farm.
...
send
. send ( message : str | bytes )
Sends a message to the given farm.
Mule
Represents uWSGI Mule.
Note
Register mules before using this. E.g.:
section.workers.set_mules_params(mules=3)
get_current
. get_current () -> Optional [ Mule ]
Returns current mule object or None if not a mule.
get_current_id
Returns current mule ID. Returns 0 if not a mule.
get_message
. get_message (
signals : bool = True , # (1)!
farms : bool = False , # (2)!
buffer_size : int = 65536 ,
timeout : int = - 1 , # (3)!
) -> str
Whether to manage signals.
Whether to manage farms.
Seconds.
Block until a mule message is received and return it.
This can be called from multiple threads in the same programmed mule.
ValueError If not in a mule.
offload
Decorator. Allows to offload function execution on this mule.
first_mule = Mule ( 1 )
@first_mule . offload ()
def for_mule ( * args , ** kwargs ):
# This function will be offloaded to and handled by mule 1.
...
send
. send ( message : str | bytes ) -> bool
Sends a message to a mule(s)/farm.
ValueError If no mules, or mule ID or farm name is not recognized.