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 shellpipe_stderr (
bool
) – Pipe stderr for reading with this connectorpipe_stdout (
bool
) – Pipe stdout for reading with this connectorpipe_stdin (
bool
) – Pipe stdin for writing with this connectortext (
bool
) – Read/write stdout, stdin, stderr in binary modecwd (
Optional
[str
]) – The current working directory for the new processenv (
Optional
[str
]) – Environment variables for the new processencoding (
Optional
[str
]) – Encoding to use in text modeexecutable (
Optional
[str
]) – The path of the executable for the processargs (
List
[str
]) – Process arguments
- _cc_receive(timeout=0.0001)[source]
Receive messages
- Parameters:
timeout (
float
) – Time to wait in seconds for a message to be receivedsize – 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
- 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 fromname (
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 fromname (
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