pysys.process.commonwrapper

Contains the pysys.process.commonwrapper.CommonProcessWrapper class that represents a process PySys has started.

CommonProcessWrapper

class pysys.process.commonwrapper.CommonProcessWrapper(command, arguments, environs, workingDir, state, timeout, stdout=None, stderr=None, displayName=None)[source]

Bases: object

Represents a process that PySys has started (or can start).

Instances of this class are returned by pysys.process.user.ProcessUser.startProcess (it’s usually not helpful to create instances directly).

Variables
  • command (str) – The full path to the executable.

  • arguments (list[str]) – A list of arguments to the command.

  • environs (dict(str,str)) – A dictionary of environment variables (key, value) for the process context execution. Use unicode strings rather than byte strings if possible; on Python 2 byte strings are converted automatically to unicode using utf-8.

  • workingDir (str) – The working directory for the process

  • state – The state of the process.

  • timeout (int) – The time in seconds for a foreground process to complete.

  • stdout (str) – The full path to the filename to write the stdout of the process, or None for no stderr stream.

  • stderr (str) – The full path to the filename to write the stderr of the process, or None for no stderr stream.

  • displayName (str) – Display name for this process (defaults to the basename if not explicitly specified). The display name is returned by calling str() on this instance. The display name and pid are returned by repr().

  • pid (int) – The process id for a running or complete process (as set by the OS), or None if it is not yet started.

  • exitStatus (int) – The process exit status for a completed process (for many processes 0 represents success), or None if it has not yet completed.

running()[source]

Check to see if a process is running.

Returns

True if the process is currently running, False if not.

signal(signal)[source]

Send a signal to a running process.

Typically this uses os.kill to send the signal.

Parameters

signal (int) – The integer signal to send to the process, e.g. process.signal(signal.SIGTERM).

Raises

pysys.exceptions.ProcessError – Raised if an error occurred whilst trying to signal the process

start()[source]

Start a process using the runtime parameters set at instantiation.

Raises
stop()[source]

Stop a running process.

Does nothing if the process is not running.

Raises

pysys.exceptions.ProcessError – Raised if an error occurred whilst trying to stop the process.

wait(timeout)[source]

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. Always provide a timeout, otherwise your test may block indefinitely!

Raises

pysys.exceptions.ProcessTimeout – Raised if the timeout is exceeded.

write(data, addNewLine=True)[source]

Write binary 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 stdin. As only binary data can be written to a process stdin, if a character string rather than a byte object is passed as the data, it will be automatically converted to a bytes object using the encoding given by locale.getpreferredencoding().

  • addNewLine – True if a new line character is to be added to the end of the data string