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.
...
-
uwsgiconf.runtime.mules.
mule_offload
(mule_or_farm: Union[str, int, Mule, Farm] = None) → Callable¶ Decorator. Use to offload function execution to a mule or a farm.
Parameters: mule_or_farm – If not set, offloads to a first mule.
-
class
uwsgiconf.runtime.mules.
Mule
(id: int)¶ Represents uWSGI Mule.
Note
Register mules before using this. E.g.:
section.workers.set_mules_params(mules=3)
Parameters: id – Mule ID. Enumeration starts with 1. -
offload
() → Callable¶ 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. ...
-
classmethod
get_current_id
() → int¶ Returns current mule ID. Returns 0 if not a mule.
-
classmethod
get_current
() → Optional[uwsgiconf.runtime.mules.Mule]¶ Returns current mule object or None if not a mule.
-
classmethod
get_message
(*, signals: bool = True, farms: bool = False, buffer_size: int = 65536, timeout: int = -1) → str¶ Block until a mule message is received and return it.
This can be called from multiple threads in the same programmed mule.
Parameters: - signals – Whether to manage signals.
- farms – Whether to manage farms.
- buffer_size –
- timeout – Seconds.
Raises: ValueError – If not in a mule.
-
send
(message: Union[str, bytes]) → bool¶ Sends a message to a mule(s)/farm.
Parameters: message – Raises: ValueError – If no mules, or mule ID or farm name is not recognized.
-
-
class
uwsgiconf.runtime.mules.
Farm
(name: str, *, mules: List[int] = 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))
Parameters: - name – Mule farm name.
- mules – Attached mules.
-
classmethod
get_farms
() → List[uwsgiconf.runtime.mules.Farm]¶ Returns a list of registered farm objects.
farms = Farm.get_farms() first_farm = farms[0] first_farm_first_mule = first_farm.mules[0]
-
offload
() → Callable¶ 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. ...
-
is_mine
¶ Returns flag indicating whether the current mule belongs to this farm.
-
classmethod
get_message
() → str¶ Reads a mule farm message.
Raises: ValueError – If not in a mule
-
send
(message: Union[str, bytes])¶ Sends a message to the given farm.
Parameters: message –