deliveryboy package¶
Module contents¶
-
class
deliveryboy.DeliveryBoy(func, transport=None, transport_params=[], executable='/home/docs/checkouts/readthedocs.org/user_builds/deliveryboy/envs/stable/bin/python', async=False, discard_excess=True, **params)[source]¶ Bases:
objectOperator for call the new process and handle input/output
When called the decorated function and non-standard modules stored in its __globals__ attribute are pickled and passed via the transport command to the newly started python process.
If an exception is raised during execution of the decorated function, this exception is pickled and reraised.
If async is False, STDOUT, STDERR and the return value of the decorated function are returned upon calling the decorated function. Otherwise only the process ID is returned; if a transport is defined, it is the process ID of the transport, otherwise the process ID of the interpreter.
After execution STDOUT and STDERR writing during execution of the callable are written to STDOUT and STDERR of the main process. This applies only to synchronous execution!
Parameters: - func (callable) – Function object that is called in the new process
- transport (str) – Transport command
- transport_params (list) – Additional arguments for the transport command.
- executable (Absolute path of python interpreter) – The python executable to be called. Default: sys.executable.
- async (bool) – If set to True, this process will not wait for the process called via the transport command to finish. Default: False
- discard_excess (bool) – If set to False, all output written to STDOUT by the new process that is not redirected gets pre- or appended accordingly to the delivery box. Default: True
Returns: Return value of the decorated callable
Raises: - deliveryboy.exceptions.DeliveryPackingError – if decorated callable is not supported, if a module cannot be added to the delivery box
- deliveryboy.exceptions.DeliveryTransportError – if calling the transport or executable fail (e.g. command not found, exit code not equal zero.
-
class
deliveryboy.DeliveryBoyDecorator(**params)[source]¶ Bases:
objectDecorator for functions
Decorated functions are pickled and passed to a newly started python process that is called via a transport command (e.g. sudo)
Parameters: - transport (str) – Transport command
- executable (Absolute path of python interpreter) – The python executable to be called. Default: sys.executable.
- async (bool) – If set to True, this process will not wait for the process called via the transport command to finish. Default: False
Submodules¶
deliveryboy.core module¶
-
class
deliveryboy.core.DeliveryBox[source]¶ Bases:
objectContainer for data exchange
-
args= None¶
-
exception= None¶
-
func= None¶
-
instance= None¶
-
kwargs= None¶
-
modules= set()¶
-
pickled_modules= set()¶
-
return_value= None¶
-
stderr= None¶
-
stdout= None¶
-
-
class
deliveryboy.core.DeliveryBoy(func, transport=None, transport_params=[], executable='/home/docs/checkouts/readthedocs.org/user_builds/deliveryboy/envs/stable/bin/python', async=False, discard_excess=True, **params)[source]¶ Bases:
objectOperator for call the new process and handle input/output
When called the decorated function and non-standard modules stored in its __globals__ attribute are pickled and passed via the transport command to the newly started python process.
If an exception is raised during execution of the decorated function, this exception is pickled and reraised.
If async is False, STDOUT, STDERR and the return value of the decorated function are returned upon calling the decorated function. Otherwise only the process ID is returned; if a transport is defined, it is the process ID of the transport, otherwise the process ID of the interpreter.
After execution STDOUT and STDERR writing during execution of the callable are written to STDOUT and STDERR of the main process. This applies only to synchronous execution!
Parameters: - func (callable) – Function object that is called in the new process
- transport (str) – Transport command
- transport_params (list) – Additional arguments for the transport command.
- executable (Absolute path of python interpreter) – The python executable to be called. Default: sys.executable.
- async (bool) – If set to True, this process will not wait for the process called via the transport command to finish. Default: False
- discard_excess (bool) – If set to False, all output written to STDOUT by the new process that is not redirected gets pre- or appended accordingly to the delivery box. Default: True
Returns: Return value of the decorated callable
Raises: - deliveryboy.exceptions.DeliveryPackingError – if decorated callable is not supported, if a module cannot be added to the delivery box
- deliveryboy.exceptions.DeliveryTransportError – if calling the transport or executable fail (e.g. command not found, exit code not equal zero.
-
class
deliveryboy.core.DeliveryBoyDecorator(**params)[source]¶ Bases:
objectDecorator for functions
Decorated functions are pickled and passed to a newly started python process that is called via a transport command (e.g. sudo)
Parameters: - transport (str) – Transport command
- executable (Absolute path of python interpreter) – The python executable to be called. Default: sys.executable.
- async (bool) – If set to True, this process will not wait for the process called via the transport command to finish. Default: False
-
deliveryboy.core.execute(inbox)[source]¶ Setup the environment and execute the decorated callable
Parameters: inbox – Pickled DeliveryBoxinstanceReturns: DeliveryBoxRaises: deliveryboy.exception.DeliveryPackingError – If callable is missing
-
deliveryboy.core.main()[source]¶ Entry function for new process
This method unpickles data from the command line, redirects STDOUT + STDERR and pickles the return value and exception
Input and output of this function are base64 encoded strings representing pickled
deliveryboy.core.DeliveryBoxobjects.
deliveryboy.exceptions module¶
-
exception
deliveryboy.exceptions.DeliveryError(*args, **kwargs)[source]¶ Bases:
ExceptionBase class for all exceptions raised by DeliveryBoy
In general derived exceptions are convenience wrappers around other exceptions.
The real exception that was raised will be delivered in the attribute real_exception.
-
real_exception= None¶
-
-
exception
deliveryboy.exceptions.DeliveryPackingError(*args, **kwargs)[source]¶ Bases:
deliveryboy.exceptions.DeliveryErrorFailure during packing of the callable
This exception is raised, if the decorated callable is not supported.
-
exception
deliveryboy.exceptions.DeliveryPickleError(*args, **kwargs)[source]¶ Bases:
deliveryboy.exceptions.DeliveryErrorFailure during (un-) pickling
This exception is raised, if picklung or unpickling fails.
-
exception
deliveryboy.exceptions.DeliveryTransportError(*args, **kwargs)[source]¶ Bases:
deliveryboy.exceptions.DeliveryErrorFailure during call of the transport command
This exception is raised, if the transport command or the executable ran into an error like the command not being found or missing permission.
deliveryboy.pickle module¶
-
class
deliveryboy.pickle.ModulePickle(modules=[], pickled=None)[source]¶ Bases:
objectSerializer for modules
This serializer accepts a list of modules and adds all source files of these modules in a TAR archive.
pickle()returns the byte stream of this archive that will be transfered in the pickled data.unpickle()takes this bytes stream and extracts the module sources in a temporary directory which is added tosys.pathin order to allow importing these modules.Parameters: - modules – list of module names
- pickled – Byte data
-
name= 'modulecontainer'¶
-
deliveryboy.pickle.pickle(data)[source]¶ Return pickled and encoded
deliveryboy.core.DeliveryBoxParameters: data ( deliveryboy.core.DeliveryBox) – delivery box to be pickledReturns: pickled/encoded delivery box Return type: bytes Raises: DeliveryPickleError – if data cannot be pickled
-
deliveryboy.pickle.unpickle(data, discard_excess=True)[source]¶ Return unpickled
deliveryboy.core.DeliveryBoxParameters: - data (bytes) – pickled/encoded delivery box
- discard_excess (bool) – If
True, additional text around the pickled data will be discarded. Default:True
Returns: deliveryboy.core.DeliveryBox, prefix, suffixReturn type: deliveryboy.core.DeliveryBox, str, strRaises: DeliveryPickleError – if data cannot be unpickled