* docs(docs): start implementing docs website * update video url * add autogenerated codebase docs for backend * precommit * update links * fix config and video * gh actions * rename * workdirs * path * path * fix doc1 * redo markdown * docs * change main folder name * simplify readme * add back architecture * Fix lint errors * lint * update poetry lock --------- Co-authored-by: Jim Su <jimsu@protonmail.com>
2.6 KiB
sidebar_label, title
| sidebar_label | title |
|---|---|
| process | opendevin.sandbox.docker.process |
DockerProcess Objects
class DockerProcess(Process)
Represents a background command execution
__init__
def __init__(id: int, command: str, result, pid: int)
Initialize a DockerProcess instance.
Arguments:
idint - The identifier of the command.commandstr - The command to be executed.result- The result of the command execution.pidint - The process ID (PID) of the command.
parse_docker_exec_output
def parse_docker_exec_output(logs: bytes) -> Tuple[bytes, bytes]
When you execute a command using exec in a docker container, the output produced will be in bytes. this function parses the output of a Docker exec command.
Example:
Considering you have a docker container named my_container up and running
$ docker exec my_container echo "Hello OpenDevin!"
>> b'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Hello OpenDevin!'
Such binary logs will be processed by this function.
The function handles message types, padding, and byte order to create a usable result. The primary goal is to convert raw container logs into a more structured format for further analysis or display.
The function also returns a tail of bytes to ensure that no information is lost. It is a way to handle edge cases and maintain data integrity.
>> output_bytes = b'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Hello OpenDevin!' >> parsed_output, remaining_bytes = parse_docker_exec_output(output_bytes)
>> print(parsed_output) b'Hello OpenDevin!'
>> print(remaining_bytes) b''
Arguments:
logsbytes - The raw output logs of the command.
Returns:
Tuple[bytes, bytes]: A tuple containing the parsed output and any remaining data.
read_logs
def read_logs() -> str
Read and decode the logs of the command.
This function continuously reads the standard output of a subprocess and processes the output using the parse_docker_exec_output function to handle binary log messages. It concatenates and decodes the output bytes into a string, ensuring that no partial messages are lost during reading.
Dummy Example:
>> cmd = 'echo "Hello OpenDevin!"' >> result = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd='.' ) >> bg_cmd = DockerProcess(id, cmd = cmd, result = result, pid)
>> logs = bg_cmd.read_logs() >> print(logs) Hello OpenDevin!
Returns:
str- The decoded logs(string) of the command.