ShellCommunicator
microbots.environment.local_docker.image_builder.ShellCommunicator
¶
Shell Communication Script A Python script to create and communicate with shell sessions. Supports interactive shell communication, command execution, and bidirectional data flow.
logger = logging.getLogger(__name__)
module-attribute
¶
CmdReturn(stdout: str, stderr: str, return_code: int)
dataclass
¶
ShellCommunicator(shell_type: str = 'bash', encoding: str = 'utf-8')
¶
A class to create and manage shell sessions with bidirectional communication.
Initialize the shell communicator.
Args: shell_type: Type of shell (only "bash" is supported) encoding: Text encoding for communication
Source code in src/microbots/environment/local_docker/image_builder/ShellCommunicator.py
encoding = encoding
instance-attribute
¶
error_queue = queue.Queue()
instance-attribute
¶
error_thread: Optional[threading.Thread] = None
instance-attribute
¶
is_running = False
instance-attribute
¶
output_callback: Optional[Callable] = None
instance-attribute
¶
output_queue = queue.Queue()
instance-attribute
¶
output_thread: Optional[threading.Thread] = None
instance-attribute
¶
process: Optional[subprocess.Popen] = None
instance-attribute
¶
shell_commands = {'bash': ['bash']}
instance-attribute
¶
shell_type = shell_type.lower()
instance-attribute
¶
close_session()
¶
Close the shell session and cleanup resources.
Source code in src/microbots/environment/local_docker/image_builder/ShellCommunicator.py
get_shell_info() -> dict
¶
Get information about the current shell session.
Returns: Dictionary with shell session information
Source code in src/microbots/environment/local_docker/image_builder/ShellCommunicator.py
is_alive() -> bool
¶
Check if the shell session is still alive.
Returns: bool: True if session is active, False otherwise
Source code in src/microbots/environment/local_docker/image_builder/ShellCommunicator.py
send_command(command: str, wait_for_output: bool = True, timeout: float = 300) -> CmdReturn
¶
Send a command to the shell session.
Args: command: Command to execute wait_for_output: Whether to wait for command output timeout: Timeout for waiting for output
Returns: CmdReturn object with stdout, stderr, and return code
Source code in src/microbots/environment/local_docker/image_builder/ShellCommunicator.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
start_session() -> bool
¶
Start a new shell session.
Returns: bool: True if session started successfully, False otherwise