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: object

Operator 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:
class deliveryboy.DeliveryBoyDecorator(**params)[source]

Bases: object

Decorator 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: object

Container 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: object

Operator 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:
class deliveryboy.core.DeliveryBoyDecorator(**params)[source]

Bases: object

Decorator 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 DeliveryBox instance
Returns:DeliveryBox
Raises: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.DeliveryBox objects.

deliveryboy.exceptions module

exception deliveryboy.exceptions.DeliveryError(*args, **kwargs)[source]

Bases: Exception

Base 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.DeliveryError

Failure 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.DeliveryError

Failure during (un-) pickling

This exception is raised, if picklung or unpickling fails.

exception deliveryboy.exceptions.DeliveryTransportError(*args, **kwargs)[source]

Bases: deliveryboy.exceptions.DeliveryError

Failure 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: object

Serializer 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 to sys.path in order to allow importing these modules.

Parameters:
  • modules – list of module names
  • pickled – Byte data
name = 'modulecontainer'
pickle()[source]

Add modules to TAR archive and return byte data of TAR archive

unpickle()[source]

Restore modules

Creates a temporary directory, add it to sys.path, opens TAR archive from byte data and extracts it into the temporary directory.

deliveryboy.pickle.pickle(data)[source]

Return pickled and encoded deliveryboy.core.DeliveryBox

Parameters:data (deliveryboy.core.DeliveryBox) – delivery box to be pickled
Returns: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.DeliveryBox

Parameters:
  • 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, suffix

Return type:

deliveryboy.core.DeliveryBox, str, str

Raises:

DeliveryPickleError – if data cannot be unpickled