Proactor¶
The proactor
module
establishes a pattern for inter-process communication using two standard
technologies:
- Configuration of processes from a configparser-compatible file.
- Message passing via RESTful web-hooks over an http transport.
Base class¶
-
class
turberfield.ipc.proactor.
Proactor
(options, loop=None, **kwargs)[source]¶ -
__init__
(options, loop=None, **kwargs)[source]¶ This class provides the basic behaviour required for a module which performs a job of work.
Parameters: - options – An argparse.Namespace or other object giving dotted-name attribute access to command line options.
- loop – An event loop compatible with asyncio.AbstractEventLoop.
-
read_config
(fObj, timeout=3)[source]¶ Read this object’s configuration file from a file stream (eg: standard input).
This method will raise asyncio.TimeoutError if the configuration is not seen within the timeout interval.
It runs within this object’s event loop.
Parameters: - fObj – A file stream object.
- timeout – A timeout interval in seconds.
-
Initiator¶
-
class
turberfield.ipc.proactor.
Initiator
(*args, **kwargs)[source]¶ The role of an Initiator is to launch executable modules as worker processes, or jobs. It is a subclass of
Proactor
.-
launch
(module, guid=None)[source]¶ Schedule a job to be spawned in a worker process.
This is a coroutine.
Parameters: - module –
A reference to a Python executable module. The module will be passed the following command line options:
--guid The guid of the job. --port A TCP port for the job to bind to. The module must read its configuration from the standard input stream.
- guid – A unique id for the job. There is usually no need to supply this parameter. It will be generated internally.
Returns: A guid to identify the new job.
- module –
-
static
next_port
(cfg, guid, busy=set())[source]¶ Calculate a value for the next available port on this host.
Parameters: - cfg – A configparser.ConfigParser object.
- guid – The global id for the Initiator which allocates ports.
- busy – A set of integer values; these are port numbers known to be busy.
Return type: integer
-
Data structures¶
-
Initiator.
Worker
(guid, port, session, module, process). The details for a worker process:¶ - guid
- A unique id which identifies a section in the configuration file.
- port
- The port (an integer) the worker process is listening on.
- session
- An optional value for the job which may be of use in web applications.
- module
- A reference to he executable Python module used to launch the job.
- process
- A reference to the Python subprocess.