Skip to content

Placet documentation

Communicator(process_name, **kwargs)

Bases: ABC

A class used to interact with the process spawned with Pexpect.

Attributes:

Name Type Description
process pexpect.spawn

The child process spawned with pexpect.

debug_mode bool

If True, running in debug mode.

Parameters:

Name Type Description Default
process_name str

Name of the child process

required

Other Parameters:

Name Type Description
debug_mode bool

If True (default is False), runs Communicator in debug mode.

save_logs bool

If True (default is True) , invoking save_debug_info().

send_delay float

The time delay before each data transfer to a child process (sometimes needed for stability). Default is Communicator._BUFFER_MAXSIZE.

__save_logs()

Open the files to store the log data of a child process

By default, the names are "log_send.txt" for logfile_send and "log_read.txt" for logfile_read.

__terminate()

Terminate the child process.

add_send_delay(time=_DELAY_BEFORE_SEND)

Add the time delay before each data transfer.

Parameters:

Name Type Description Default
time float

The time delay.

_DELAY_BEFORE_SEND

close()

Close all the associated threads running.

flush()

Flush the child process buffer

readline() abstractmethod

Read the line from the child process.

Returns:

Type Description
str

The line of the data received from the child process.

readlines(N_lines, timeout=_BASE_TIMEOUT)

Read several lines from the child process.

Parameters:

Name Type Description Default
N_lines int

Number of lines to read.

required
timeout float

Timeout of the reader before raising the exception. [30.11.2022] - No effect anymore. The parameter is kept for compatibility.

_BASE_TIMEOUT

Returns:

Type Description
list

The list of the lines received from the child process.

save_debug_info(filename='debug_data.pkl')

Save the debug info to a files.

Parameters:

Name Type Description Default
filename str

Name of the file.

'debug_data.pkl'

skipline(timeout=_BASE_TIMEOUT)

Skip the line of the child's process output.

Parameters:

Name Type Description Default
timeout float

Timeout of the reader before raising the exception. [30.11.2022] - No effect anymore. The parameter is kept for compatibility.

_BASE_TIMEOUT

writeline(command, skipline=True, timeout=_BASE_TIMEOUT, **kwargs)

Send the line to a child process.

There is an expect call to search for a prompt defined in Communicator._TERMINAL_SPECIAL_SYMBOL (default value is '% ') before writing to a process - process.write(). Doing so, we make sure that we do not try to write while the process is still busy with the previous command. We set the default timeout of Communicator._BASE_TIMEOUT.

The optional parameters expect_before and expect_after used to specify when to use the expect command in between writing the command. There has to be always 1 expect call after command execution. By default, one expect call is used before writing the command. In certain situations, one would want to do the expect call after the command is written. The parameter __expect_block controls the use of expect commands - making sure, only 1 expect command is executed in between 2 commands.

Parameters:

Name Type Description Default
command str

Command to execute

required
skipline bool

If True, reads the command that was sent to a child process from child's process output This flag depends on the default running mode of pexpect. By default, it outputs to stdout what was just send to stdin

True
timeout float

Timeout of the reader before raising the exception. [30.11.2022] - No effect anymore. The parameter is kept for compatibility.

_BASE_TIMEOUT

Other Parameters:

Name Type Description
expect_before bool

If True (default is True), expect is invoked before writing the command.

expect_after bool

If True (default is False), expect is invoked after writing the command.

no_expect bool

If True (default is False), no expect is invoked, ignoring __expect_block

Returns:

Type Description
str

The command that was sent to a child process