cis_interface.drivers package¶
Subpackages¶
Submodules¶
cis_interface.drivers.AsciiFileInputDriver module¶
-
class
cis_interface.drivers.AsciiFileInputDriver.
AsciiFileInputDriver
(name, args, skip_AsciiFile=False, **kwargs)[source]¶ Bases:
cis_interface.drivers.FileInputDriver.FileInputDriver
Class that sends lines from an ASCII file.
Parameters: - name (str) – Name of the queue that messages should be sent to.
- args (str or dict) – Path to the file that messages should be read from or dictionary containing the filepath and other keyword arguments to be passed to the created AsciiFile object.
- skip_AsciiFile (bool, optional) – If True, the AsciiFile instance is not created. Defaults to False.
- **kwargs – Additional keyword arguments are passed to parent class.
-
file_kwargs
¶ dict – Arguments used to create AsciiFile instance.
-
file
¶ AsciiFile.AsciiFile
– Associated special class for ASCII file.
-
eof_msg
¶ str – Message indicating end of file.
cis_interface.drivers.AsciiFileOutputDriver module¶
-
class
cis_interface.drivers.AsciiFileOutputDriver.
AsciiFileOutputDriver
(name, args, skip_AsciiFile=False, **kwargs)[source]¶ Bases:
cis_interface.drivers.FileOutputDriver.FileOutputDriver
Class to handle output line by line to an ASCII file.
Parameters: - name (str) – Name of the output queue to receive messages from.
- args (str or dict) – Path to the file that messages should be written to or dictionary containing the filepath and other keyword arguments to be passed to the created AsciiFile object.
- skip_AsciiFile (bool, optional) – If True, the AsciiFile instance is not created. Defaults to False.
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
-
file_kwargs
¶ dict – Arguments used to create AsciiFile instance.
-
file
¶ AsciiFile.AsciiFile
– Associated special class for ASCII file.
-
eof_msg
¶ str – Message indicating end of file.
cis_interface.drivers.AsciiTableInputDriver module¶
-
class
cis_interface.drivers.AsciiTableInputDriver.
AsciiTableInputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.AsciiFileInputDriver.AsciiFileInputDriver
Class to handle input from an ASCII table.
Parameters: - name (str) – Name of the input queue to send messages to.
- args (str or dict) – Path to the file that messages should be read from or dictionary containing the filepath and other keyword arguments to be passed to the created AsciiTable object.
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
- Attributes (in additon to parent class’s):
- file (
AsciiTable.AsciiTable
): Associated special class for - ASCII table.
- as_array (bool): If True, the table contents are sent all at once as an
- array. Defaults to False if not set in args dict.
- file (
cis_interface.drivers.AsciiTableOutputDriver module¶
-
class
cis_interface.drivers.AsciiTableOutputDriver.
AsciiTableOutputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.AsciiFileOutputDriver.AsciiFileOutputDriver
Class to handle output of received messages to an ASCII table.
Parameters: - name (str) – Name of the output queue to receive messages from.
- args (str or dict) – Path to the file that messages should be written to or dictionary containing the filepath and other keyword arguments to be passed to the created AsciiTable object.
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
- Attributes (in additon to parent class’s):
- file (
AsciiTable.AsciiTable
): Associated special class for - ASCII table.
- as_array (bool): If True, the table contents are received all at once
- as an array. Defaults to False if not set in args dict.
- file (
cis_interface.drivers.Driver module¶
-
class
cis_interface.drivers.Driver.
Driver
(name, yml={}, namespace=None, rank=None, workingDir=None)[source]¶ Bases:
threading.Thread
Base class for all drivers.
Parameters: - name (str) – Driver name.
- yml (dict, optional) – Dictionary of yaml specification options for this driver. Defaults to empty dict.
- namespace (str, optional) – Namespace for set of drivers running together. If not provided, the environment variable ‘PSI_NAMESPACE’ is used.
- rank (int, optional) – Rank of the integration. Defaults to None.
- workingDir (str, optional) – Working directory. If not provided, the current working directory is used.
-
name
¶ str – Driver name.
-
sleeptime
¶ float – Time that driver should sleep for when sleep called.
-
longsleep
¶ float – Time that the driver will sleep for when waiting for longer tasks to complete (10x longer than sleeptime).
-
timeout
¶ float – Maximum time that should be spent waiting on a process.
-
yml
¶ dict – Dictionary of yaml specification options for this driver.
-
namespace
¶ str – Namespace for set of drivers running together.
-
rank
¶ int – Rank of the integration.
-
workingDir
¶ str – Working directory.
-
critical
(fmt_str='', *args)[source]¶ Log a critical message that is prepended with the driver class and name.
Parameters: - fmt_str (str, optional) – Format string.
- *args – Additional arguments are formated using the format string.
-
debug
(fmt_str='', *args)[source]¶ Log a debug message that is prepended with the driver class and name.
Parameters: - fmt_str (str, optional) – Format string.
- *args – Additional arguments are formated using the format string.
-
display
(fmt_str='', *args)[source]¶ Log a message at level 1000 that is prepended with the driver class and name. These messages will always be printed.
Parameters: - fmt_str (str, optional) – Format string.
- *args – Additional arguments are formated using the format string.
-
error
(fmt_str='', *args)[source]¶ Log an error message that is prepended with the driver class and name.
Parameters: - fmt_str (str, optional) – Format string.
- *args – Additional arguments are formated using the format string.
-
exception
(fmt_str='', *args)[source]¶ Log an exception message that is prepended with the driver class ane name.
Parameters: - fmt_str (str, optional) – Format string.
- *args – Additional arguments are formated using the format string.
-
info
(fmt_str='', *args)[source]¶ Log an info message that is prepended with the driver class and name.
Parameters: - fmt_str (str, optional) – Format string.
- *args – Additional arguments are formated using the format string.
-
logger_prefix
¶ Prefix to add to logger messages.
-
sched_task
(t, func, args=[], kwargs={})[source]¶ Schedule a task that will be executed after a certain time has elapsed.
Parameters:
cis_interface.drivers.FileInputDriver module¶
-
class
cis_interface.drivers.FileInputDriver.
FileInputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.IODriver.IODriver
Class that sends messages read from a file.
Parameters: - Attributes (in additon to parent class’s):
- args (str): Path to the file that messages should be read from.
fd (file-like): File descriptor for the input file while it is open.
lock (
threading.Lock
): Lock to be used when accessing file.
cis_interface.drivers.FileOutputDriver module¶
-
class
cis_interface.drivers.FileOutputDriver.
FileOutputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.IODriver.IODriver
Class to handle output of received messages to a file.
Parameters: - Attributes (in addition to parent class’s):
- args (str): Path to the file that messages should be written to.
fd (file-like): File descriptor for the target file if open.
lock (
threading.Lock
): Lock to be used when accessing file.
cis_interface.drivers.GCCModelDriver module¶
-
class
cis_interface.drivers.GCCModelDriver.
GCCModelDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.ModelDriver.ModelDriver
Class from running gcc compiled driveres.
Parameters: - name (str) – Driver name.
- args (str or list) – Argument(s) for running the model on the command line. If the first element ends with ‘.c’, the driver attempts to compile the code with the necessary interface include directories. Additional arguments that start with ‘-I’ are included in the compile command. Others are assumed to be runtime arguments.
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
- Attributes (in additon to parent class’s):
- compiled (bool): True if the compilation was succesful. False otherwise.
cis_interface.drivers.IODriver module¶
-
class
cis_interface.drivers.IODriver.
IODriver
(name, suffix='', **kwargs)[source]¶ Bases:
cis_interface.drivers.Driver.Driver
Base driver for any driver that requires access to a message queue.
Parameters: - Attributes (in addition to parent class’s):
- state (str): Description of the last operation performed by the driver.
numSent (int): The number of messages sent to the queue.
numReceived (int): The number of messages received from the queue.
env (dict): Environment variables.
mq (
sysv_ipc.MessageQueue
): Message queue.
-
graceful_stop
(timeout=0, **kwargs)[source]¶ Stop the IODriver, first draining the message queue.
Parameters: - timeout (float, optional) – Max time that should be waited. Defaults to 0 and is set to attribute timeout.
- **kwargs – Additional keyword arguments are passed to the parent class’s graceful_stop method.
-
ipc_recv
()[source]¶ Receive a message smaller than maxMsgSize.
Returns: The received message. Return type: str
-
ipc_recv_nolimit
()[source]¶ Receive a message larger than maxMsgSize in multiple parts.
Returns: The complete received message. Return type: str
-
ipc_send
(data)[source]¶ Send a message smaller than maxMsgSize.
Parameters: str – The message to be sent.
-
ipc_send_nolimit
(data)[source]¶ Send a message larger than maxMsgSize in multiple parts.
Parameters: str – The message to be sent.
-
n_ipc_msg
¶ int – The number of messages in the queue.
-
printStatus
(beg_msg='', end_msg='')[source]¶ Print information on the status of the IODriver.
Parameters:
-
recv_wait
(timeout=0)[source]¶ Receive a message smaller than maxMsgSize. Unlike ipc_recv, recv_wait will wait until there is a message to receive or the queue is closed.
Parameters: timeout (float, optional) – Max time that should be waited. Defaults to 0 and is set to attribute timeout. Returns: The received message. Return type: str
-
recv_wait_nolimit
(timeout=0)[source]¶ Receive a message larger than maxMsgSize. Unlike ipc_recv, recv_wait will wait until there is a message to receive or the queue is closed.
Parameters: timeout (float, optional) – Max time that should be waited. Defaults to 0 and is infinite. Returns: The received message. Return type: str
cis_interface.drivers.MatInputDriver module¶
-
class
cis_interface.drivers.MatInputDriver.
MatInputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.FileInputDriver.FileInputDriver
Class that sends pickled dictionaries of matricies read from a .mat file.
Parameters: - Attributes (in addition to parent class’s):
cis_interface.drivers.MatOutputDriver module¶
-
class
cis_interface.drivers.MatOutputDriver.
MatOutputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.FileOutputDriver.FileOutputDriver
Class to handle output to .mat Matlab files.
Parameters: - Attributes (in addition to parent class’s):
cis_interface.drivers.MatlabModelDriver module¶
-
class
cis_interface.drivers.MatlabModelDriver.
MatlabModelDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.ModelDriver.ModelDriver
Base class for running Matlab models.
Parameters: -
started_matlab
¶ bool – True if the driver had to start a new matlab engine. False otherwise.
-
screen_session
¶ str – Screen session that Matlab was started in.
-
mlengine
¶ object – Matlab engine used to run script.
-
mlsession
¶ str – Name of the Matlab session that was started.
-
-
cis_interface.drivers.MatlabModelDriver.
start_matlab
()[source]¶ Start a Matlab shared engine session inside a detached screen session.
Returns: Name of the screen session running matlab. Return type: str
cis_interface.drivers.ModelDriver module¶
-
class
cis_interface.drivers.ModelDriver.
ModelDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.Driver.Driver
Base class form Model drivers.
Parameters: - Attributes (in additon to parent class’s):
- args (list): Argument(s) for running the model on the command line.
process (
subprocess.Popen
): Process used to run the model. env (dict): Dictionary of environment variables.
cis_interface.drivers.PythonModelDriver module¶
-
class
cis_interface.drivers.PythonModelDriver.
PythonModelDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.ModelDriver.ModelDriver
Class for running Python models.
Parameters: - Attributes (in additon to parent class’s):
cis_interface.drivers.RMQClientDriver module¶
-
class
cis_interface.drivers.RMQClientDriver.
RMQClientDriver
(name, args=None, **kwargs)[source]¶ Bases:
cis_interface.drivers.RMQDriver.RMQDriver
,cis_interface.drivers.RPCDriver.RPCDriver
Class for handling client side RPC type RabbitMQ communication.
Parameters: - name (str) – The name of the local IPC message queues that the driver should use.
- args (str, optional) – The name of the server RabbitMQ message queue that requests should be sent to. Defaults to name + ‘_SERVER’ if not set.
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
-
request_queue
¶ str – The name of RabbitMQ message queue that requests will be sent to. (See args above).
-
response
¶ str – Response to the most recent request.
-
corr_id
¶ str – Correlation id for the most recent request.
cis_interface.drivers.RMQDriver module¶
-
class
cis_interface.drivers.RMQDriver.
RMQDriver
(name, queue='', routing_key=None, **kwargs)[source]¶ Bases:
cis_interface.drivers.Driver.Driver
Class for handling basic RabbitMQ communications.
Parameters: - name (str) – The name of the driver.
- queue (str, optional) – Name of the queue that messages will be received from. If and empty string, the queue is exclusive to this connection. Defaults to ‘’.
- routing_key (str, optional) – Routing key that should be used when the queue is bound. If None, the queue name is used. Defaults to None.
- user (str, optional) – RabbitMQ server username. Defaults to config option ‘user’ in section ‘rmq’.
- host (str, optional) – RabbitMQ server host. Defaults to config option ‘host’ in section ‘rmq’ if it exists and the output of socket.gethostname() if it does not.
- vhost (str, optional) – RabbitMQ server virtual host. Defaults to config option ‘vhost’ in section ‘rmq’.
- passwd (str, optional) – RabbitMQ server password. Defaults to config option ‘password’ in section ‘rmq’.
- exchange (str, optional) – RabbitMQ exchange. Defaults to ‘namespace’ attribute which is set from the config option ‘namespace’ in the section ‘rmq’.
- exclusive (bool, optional) – If True, the queue that is created can only be used by this driver. Defaults to False. If a queue name is not provided, it is assumed exclusive.
-
user
¶ str – RabbitMQ server username.
-
passwd
¶ str – RabbitMQ server password.
-
host
¶ str – RabbitMQ server host.
-
vhost
¶ str – RabbitMQ server virtual host.
-
exchange
¶ str – RabbitMQ exchange name.
-
connection
¶ pika.Connection
– RabbitMQ connection.
-
channel
¶ pika.Channel
– RabbitMQ channel.
-
queue
¶ str – Name of the queue that messages will be received from. If an empty string, the queue is exclusive to this connection.
-
routing_key
¶ str – Routing key that should be used when the queue is bound. If None, the queue name is used.
-
times_connected
¶ int – Number of times the connection has been established/re-established.
-
connection_parameters
¶ pika.connection.ConnectionParameters
– Connection parameters.
-
creds
¶ pika.credentials.PlainCredentials
– Server credentials.
-
is_open
¶ bool – True if connection ready for messages, False otherwise.
-
is_stable
¶ bool – True if the connection ready for messages and not about to close. False otherwise.
-
n_rmq_msg
¶ int – Number of messages in the queue.
-
on_bindok
(unused_frame)[source]¶ Actions to perform once the queue is succesfully bound. Start consuming messages.
-
on_channel_closed
(channel, reply_code, reply_text)[source]¶ Actions to perform when the channel is closed. Close the connection.
-
on_channel_open
(channel)[source]¶ Actions to perform after a channel is opened. Add the channel close callback and setup the exchange.
-
on_connection_closed
(connection, reply_code, reply_text)[source]¶ Actions that must be taken when the connection is closed. Set the channel to None. If the connection is meant to be closing, stop the IO loop. Otherwise, wait 5 seconds and try to reconnect.
-
on_connection_open
(unused_connection)[source]¶ Actions that must be taken when the connection is opened. Add the close connection callback and open the RabbitMQ channel.
-
on_connection_open_error
(unused_connection)[source]¶ Actions that must be taken when the connection fails to open.
-
on_exchange_declareok
(unused_frame)[source]¶ Actions to perform once an exchange is succesfully declared. Set up the queue.
-
on_nmsg_request
(method_frame)[source]¶ Actions to perform once the queue is declared for message count.
-
on_queue_declareok
(method_frame)[source]¶ Actions to perform once the queue is succesfully declared. Bind the queue.
-
rmq_send
(data)[source]¶ Send a message smaller than maxMsgSize to the RMQ queue.
Parameters: data (str) – The message to be sent. Returns: True if the message was sent succesfully. False otherwise. Return type: bool
cis_interface.drivers.RMQInputDriver module¶
Module for receiving input from a RabbitMQ server.
-
class
cis_interface.drivers.RMQInputDriver.
RMQInputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.RMQDriver.RMQDriver
,cis_interface.drivers.IODriver.IODriver
Driver for receiving input from a RabbitMQ server.
Parameters: - Attributes (in addition to parent class’s):
cis_interface.drivers.RMQOutputDriver module¶
Module for sending output to a RabbitMQ server.
-
class
cis_interface.drivers.RMQOutputDriver.
RMQOutputDriver
(name, args, **kwargs)[source]¶ Bases:
cis_interface.drivers.RMQDriver.RMQDriver
,cis_interface.drivers.IODriver.IODriver
Driver for sending output to a RabbitMQ server.
Parameters: - Attributes (in addition to parent class’s):
cis_interface.drivers.RMQServerDriver module¶
-
class
cis_interface.drivers.RMQServerDriver.
RMQServerDriver
(name, args=None, **kwargs)[source]¶ Bases:
cis_interface.drivers.RMQDriver.RMQDriver
,cis_interface.drivers.RPCDriver.RPCDriver
Class for handling server side RPC type RabbitMQ communication.
Parameters: - name (str) – The name of the local IPC message queues that the driver should use.
- args (str, optional) – The name of the RabbitMQ message queue that the driver should connect to. Defaults to name + ‘_SERVER’ if not set.
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
- Attributes (in addition to the parent class’s):
- clients (set): The unique clients subscribed to this server.
-
n_clients
¶ int – The number of clients that are submitting requests to the server.
cis_interface.drivers.RPCDriver module¶
-
class
cis_interface.drivers.RPCDriver.
RPCDriver
(name, args=None, **kwargs)[source]¶ Bases:
cis_interface.drivers.Driver.Driver
Base class for any driver that requires to access to input & output queues for RPC type functionality.
Parameters: - name (str) – The name of the message queue set that the driver should connect to. (name + “_IN” and name + “_OUT”)
- **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
- Attributes (in addition to parent class’s):
- iipc (
cis_interface.drivers.IODriver
): Driver for the input - message queue.
- oipc (
cis_interface.drivers.IODriver
): Driver for the output - message ueue.
- iipc (
-
env
¶ dict – Environment variables.
-
ipc_recv
(use_output=False)[source]¶ Receive message smaller than maxMsgSize from the input queue.
Parameters: use_output (bool, optional) – If True, the message is received from the output queue instead of the input one. Returns: The received message. Return type: str
-
ipc_recv_nolimit
(use_output=False)[source]¶ Receive message larger than maxMsgSize from the output queue.
Parameters: use_output (bool, optional) – If True, the message is received from the output queue instead of the input one. Returns: The received message. Return type: str
-
ipc_send
(data, use_input=False)[source]¶ Send message smaller than maxMsgSize to the output queue.
Parameters:
-
ipc_send_nolimit
(data, use_input=False)[source]¶ Send message larger than maxMsgSize to the input queue.
Parameters:
-
n_msg_in
¶ int – The number of messages in the input queue.
-
n_msg_out
¶ int – The number of messages in the output queue.
-
recv_wait
(use_output=False, timeout=0.0)[source]¶ Receive a message smaller than maxMsgSize. This method will wait until there is a message in the queue to return or the queue is closed.
Parameters: Returns: The received message.
Return type:
Module contents¶
IO and Model drivers.