Pipettor Library¶
Function Interface¶
- run(cmds, stdin=None, stdout=None, stderr=<class 'pipettor.devices.DataReader'>, logger=None, logLevel=None)[source]¶
Construct and run a process pipeline.
- Parameters:
cmds – A list (or tuple) of arguments for a single process, or a list of such lists for a pipeline. Arguments are converted to strings.
stdin – Input to the first process. Can be None (inherit), filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataWriterobject.stdout – Output from the last process. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject.stderr – stderr for the pipeline. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject. It may also be the classpipettor.DataReaderitself. See discussion below.logger – Name of the logger or a Logger instance. If
None, the defaultpipettorlogger is used.logLevel – Log level to use instead of the default.
- runout(cmds, stdin=None, stderr=<class 'pipettor.devices.DataReader'>, binary=False, logger=None, logLevel=None, buffering=-1, encoding=None, errors=None, newline=None)[source]¶
Construct and run a process pipeline, returning the output.
- Parameters:
cmds – A list (or tuple) of arguments for a single process, or a list of such lists for a pipeline. Arguments are converted to strings.
stdin – Input to the first process. Can be None (inherit), filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataWriterobject.stdout – Output from the last process. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject.stderr – stderr for the pipeline. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject. It may also be the classpipettor.DataReaderitself. See discussion below.logger – Name of the logger or a Logger instance. If
None, the defaultpipettorlogger is used.logLevel – Log level to use instead of the default.
buffering – controls buffering. See open() for more details.
encoding – name of the encoding used to decode or encode the file See open() for more details.
errors – how encoding errors are handled. See open() for more details.
newline – controls how universal newlines works See open() for more details.
- Raises:
pipettor.ProcessException – if the a process in pipeline exits with a non-zero status
Use
str.splitlines()to split the result into lines.They specification of
stderrcontrols how errors are reported. If apipettor.DataReaderclass is provided forstderr, aDataReaderobject will be created from it for each process to collect that processes stderr output. If the pipeline fails, the contents of stderr from the first process that failed will be included in thepipettor.ProcessExceptionobject. If an instance ofpipettor.DataReaderis provided, stderr from all processes is combined and that is returned in the failure. It is recommended that a DataReader object be created witherrors="backslashreplace"to prevent invalid UTF-8 characters from generating confusing errors.
- runlex(cmds, stdin=None, stdout=None, stderr=<class 'pipettor.devices.DataReader'>, logger=None, logLevel=None)[source]¶
Call
pipettor.run(), first splitting commands specified as strings are split into arguments using shlex.split.See
run()for details.
- runlexout(cmds, stdin=None, stderr=<class 'pipettor.devices.DataReader'>, logger=None, logLevel=None, buffering=-1, encoding=None, errors=None)[source]¶
Call
pipettor.runout(), first splitting commands specified as strings are split into arguments using shlex.split.See
runout()for details.
Pipeline Classes¶
- class Pipeline(cmds, *, stdin=None, stdout=None, stderr=<class 'pipettor.devices.DataReader'>, logger=None, logLevel=None)[source]¶
- Parameters:
cmds – A list (or tuple) of arguments for a single process, or a list of such lists for a pipeline. Arguments are converted to strings.
stdin – Input to the first process. Can be None (inherit), filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataWriterobject.stdout – Output from the last process. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject.stderr – stderr for the pipeline. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject. It may also be the classpipettor.DataReaderitself. See discussion below.logger – Name of the logger or a Logger instance. If
None, the defaultpipettorlogger is used.logLevel – Log level to use instead of the default.
- property finished¶
determined if been detected as finished (waited on)
- poll()[source]¶
Check if all of the processes have completed. Return True if it has, False if it hasn’t.
- property running¶
determined if this process has been running
- shutdown()[source]¶
Close down the pipeline prematurely. If the pipeline is running, it’s killed. This does not report errors from child process and differs from wait in the fact that it doesn’t start the pipeline if it has not been started, just frees up open pipes. Primary intended for error recovery
- class Popen(cmds, mode='r', *, stdin=None, stdout=None, stderr=None, logger=None, logLevel=None, buffering=-1, encoding=None, errors=None, newline=None)[source]¶
File-like object of processes to read from or write to a Pipeline. Only one of
stdinorstdoutmaybe specified, with the other end being read or written via the Popen instance.Read pipeline (‘r’): stdin → cmd[0] → … → cmd[n] → Popen
Write pipeline (‘w’): Popen → cmd[0] → … → cmd[n] → stdout
- Parameters:
mode – specifies the mode in which the file is opened. It defaults to ‘r’. See open() for more details.
cmds – A list (or tuple) of arguments for a single process, or a list of such lists for a pipeline. Arguments are converted to strings.
stdin – Input to the first process. Can be None (inherit), filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataWriterobject.stdout – Output from the last process. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject.stderr – stderr for the pipeline. Can be None (inherit), a filename, file-like object, file descriptor, a
pipettor.Fileobject, or apipettor.DataReaderobject. It may also be the classpipettor.DataReaderitself. See discussion below.logger – Name of the logger or a Logger instance. If
None, the defaultpipettorlogger is used.logLevel – Log level to use instead of the default.
buffering – controls buffering. See open() for more details.
encoding – name of the encoding used to decode or encode the file See open() for more details.
errors – how encoding errors are handled. See open() for more details.
newline – controls how universal newlines works See open() for more details.
- Raises:
pipettor.ProcessException – if the a process in pipeline exits with a non-zero status
They specification of
stderrcontrols how errors are reported. If apipettor.DataReaderclass is provided forstderr, aDataReaderobject will be created from it for each process to collect that processes stderr output. If the pipeline fails, the contents of stderr from the first process that failed will be included in thepipettor.ProcessExceptionobject. If an instance ofpipettor.DataReaderis provided, stderr from all processes is combined and that is returned in the failure. It is recommended that a DataReader object be created witherrors="backslashreplace"to prevent invalid UTF-8 characters from generating confusing errors.- property closed¶
bool. True if the file has been closed.
- Type:
closed
- failed()¶
check if any process failed, call after poll() or wait()
- property finished¶
determined if been detected as finished (waited on)
- kill(sig=Signals.SIGTERM)¶
send a signal to all of the processes in the pipeline
- property running¶
determined if this process has been running
- shutdown()¶
Close down the pipeline prematurely. If the pipeline is running, it’s killed. This does not report errors from child process and differs from wait in the fact that it doesn’t start the pipeline if it has not been started, just frees up open pipes. Primary intended for error recovery
- start()¶
start processes
Process I/O Classes¶
- class DataReader(*, binary=False, buffering=-1, encoding=None, errors=None, newline=None)[source]¶
Object to asynchronously read data from process into memory via a pipe. A thread is use to prevent deadlock when both reading and writing to a child pipeline.
Specifying binary access results in data of type bytes, otherwise str type is returned. The buffering, encoding, and errors arguments are as used in the open() function.
A reader maybe read from multiple process.
- property data¶
return buffered data as a string or bytes
- class DataWriter(data, *, buffering=-1, encoding=None, errors=None, newline=None)[source]¶
Object to asynchronously write data to process from memory via a pipe. A thread is use to prevent deadlock when both reading and writing to a child pipeline. Text or binary output is determined by the type of data.
The buffering, encoding, and errors arguments are as used in the open() function.
Logging Control¶
- LOGGER_NAME = 'pipettor'¶
Name of default logger for pipettor
- setDefaultLogging(logger, level)[source]¶
Set both default logger and level. Either can be None to leave as default
- setDefaultLogger(logger)[source]¶
Set the default pipettor logger used in logging command and errors. If None, removes default logging. The logger can be the name of a logger or the logger Default logger is
pipettor