Subprocess Environment¶
- class oscopilot.environments.subprocess_env.SubprocessEnv[source]¶
Bases:
BaseEnvA class representing an environment for executing code using subprocesses.
This class manages the execution of code in subprocesses, providing methods for preprocessing code, starting and terminating processes, handling output streams, and executing code steps.
It inherits from BaseEnv, which provides basic environment functionality.
- detect_active_line(line)[source]¶
Detects an active line indicator in the output line.
- Parameters:
line (str) – The output line from the subprocess.
- Returns:
The active line number if detected, else None.
- Return type:
int or None
- detect_end_of_execution(line)[source]¶
Detects an end of execution marker in the output line.
- Parameters:
line (str) – The output line from the subprocess.
- Returns:
True if end of execution marker is detected, else False.
- Return type:
bool
- handle_stream_output(stream, is_error_stream)[source]¶
Handles the streaming output from the subprocess.
- Parameters:
stream – The output stream to handle.
is_error_stream (bool) – Indicates if the stream is the error stream.
- line_postprocessor(line)[source]¶
Post-processes an output line from the subprocess.
- Parameters:
line (str) – The output line from the subprocess.
- Returns:
The processed line or None if line should be discarded.
- Return type:
str or None
- preprocess_code(code)[source]¶
Preprocesses code before execution.
This method inserts an end_of_execution marker and optionally adds active line markers.
- Parameters:
code (str) – The code to preprocess.
- Returns:
The preprocessed code.
- Return type:
str