Class ProcessWrapper
source code
Unix process wrapper for process execution and management.
The unix process wrapper provides the ability to start and stop an
external process, setting the process environment, working directory and
state i.e. a foreground process in which case a call to the start() method will not return until the process has
exited, or a background process in which case the process is started in a
separate thread allowing concurrent execution within the testcase.
Processes started in the foreground can have a timeout associated with
them, such that should the timeout be exceeded, the process will be
terminated and control passed back to the caller of the method. The
wrapper additionally allows control over logging of the process stdout
and stderr to file, and writing to the process stdin.
Usage of the class is to first create an instance, setting all runtime
parameters of the process as data attributes to the class instance via
the constructor. The process can then be started and stopped via the start() and stop() methods of the class, as well as interrogated for
its executing status via the running() method, and waited for its completion via the
wait() method. During process execution the
self.pid and seld.exitStatus data attributes
are set within the class instance, and these values can be accessed
directly via it's object reference.
|
|
__init__(self,
command,
arguments,
environs,
workingDir,
state,
timeout,
stdout=None,
stderr=None)
Create an instance of the process wrapper. |
source code
|
|
|
|
write(self,
data,
addNewLine=True)
Write data to the stdin of the process. |
source code
|
|
|
integer
|
running(self)
Check to see if a process is running, returning true if running. |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
start(self)
Start a process using the runtime parameters set at instantiation. |
source code
|
|
|
integer
|
exitStatus
The process exit status for a completed process
|
|
integer
|
pid
The process id for a running or complete process (as set by the OS)
|
__init__(self,
command,
arguments,
environs,
workingDir,
state,
timeout,
stdout=None,
stderr=None)
(Constructor)
| source code
|
Create an instance of the process wrapper.
- Parameters:
command - The full path to the command to execute
arguments - A list of arguments to the command
environs - A dictionary of environment variables (key, value) for the
process context execution
workingDir - The working directory for the process
state - The state of the process (pysys.constants.FOREGROUND or pysys.constants.BACKGROUND
timeout - The timeout in seconds to be applied to the process
stdout - The full path to the filename to write the stdout of the process
stderr - The full path to the filename to write the sdterr of the process
|
|
Write data to the stdin of the process.
Note that when the addNewLine argument is set to true, if a new line
does not terminate the input data string, a newline character will be
added. If one already exists a new line character will not be added.
Should you explicitly require to add data without the method appending a
new line charater set addNewLine to false.
- Parameters:
data - The data to write to the process stdout
addNewLine - True if a new line character is to be added to the end of the
data string
|
|
Check to see if a process is running, returning true if running.
- Returns: integer
- The running status (True / False)
|
|
Wait for a process to complete execution.
The method will block until either the process is no longer running,
or the timeout is exceeded. Note that the method will not terminate the
process if the timeout is exceeded.
- Parameters:
timeout - The timeout to wait in seconds
- Raises:
|
|
Stop a process running.
- Raises:
ProcessError - Raised if an error occurred whilst trying to stop the process
|
|
Send a signal to a running process.
- Parameters:
signal - The integer signal to send to the process
- Raises:
ProcessError - Raised if an error occurred whilst trying to signal the process
|
|
Start a process using the runtime parameters set at instantiation.
- Raises:
ProcessError - Raised if there is an error creating the process
ProcessTimeout - Raised in the process timed out (foreground process only)
|