18. cc_process

18.1. Process Channel

module:

cc_process

synopsis:

CChannel implementation for process execution.

The CCProcess channel provides functionality to start a process and to communicate with it.

class pykiso.lib.connectors.cc_process.CCProcess(shell=False, pipe_stderr=False, pipe_stdout=True, pipe_stdin=False, text=True, cwd=None, env=None, encoding=None, executable=None, args=[], **kwargs)[source]

Channel to run processes

Initialize a process

Parameters:
  • shell (bool) – Start process through shell

  • pipe_stderr (bool) – Pipe stderr for reading with this connector

  • pipe_stdout (bool) – Pipe stdout for reading with this connector

  • pipe_stdin (bool) – Pipe stdin for writing with this connector

  • text (bool) – Read/write stdout, stdin, stderr in binary mode

  • cwd (Optional[str]) – The current working directory for the new process

  • env (Optional[str]) – Environment variables for the new process

  • encoding (Optional[str]) – Encoding to use in text mode

  • executable (Optional[str]) – The path of the executable for the process

  • args (List[str]) – Process arguments

_cc_close()[source]

Close the channel.

Return type:

None

_cc_open()[source]

Implement abstract method

Return type:

None

_cc_receive(timeout=0.0001)[source]

Receive messages

Parameters:
  • timeout (float) – Time to wait in seconds for a message to be received

  • size – unused

Return type:

Union[str, ByteString]

return The received message

_cc_send(msg, **kwargs)[source]

Execute process commands or write data to stdin

Parameters:

msg (Union[str, ByteString]) – data to send

Raises:

CCProcessError – Stdin pipe is not enabled

Return type:

None

_cleanup()[source]

Cleanup threads and process objects

Return type:

None

static _create_message_dict(msg)[source]

Create a dict from an entry in the process queue

Parameters:

msg (Union[ProcessMessage, ProcessExit]) – The message to convert

Return type:

dict

Returns:

The dictionary

_read_existing()[source]

Read buffered messages that where already received from the process. Messages from the same stream are combined. This is only used in binary mode.

Return type:

Optional[ProcessMessage]

Returns:

Existing messages

_read_thread(stream, name)[source]

Thread for reading data from stdout or stderr

Parameters:
  • stream (IO) – The stream to read from

  • name (str) – The name of the stream

Return type:

None

_start_read_thread(stream, name)[source]

Start a read thread

Parameters:
  • stream (IO) – The stream to read from

  • name (str) – The name of the stream

Return type:

Thread

Returns:

The thread object

start(executable=None, args=None)[source]

Start a process

Parameters:
  • executable (Optional[str]) – The executable path. Default to path specified in yaml if not given.

  • args (Optional[List[str]]) – The process arguments. Default to arguments specified in yaml if not given.

Raises:

CCProcessError – Process is already running

exception pykiso.lib.connectors.cc_process.CCProcessError[source]
class pykiso.lib.connectors.cc_process.ProcessExit(exit_code)[source]

Contains information about process exit

class pykiso.lib.connectors.cc_process.ProcessMessage(stream, data)[source]

Holds the data that is read from the process