Execute a single script Args: script_config: script configuration run_time: run time (seconds), if None use script configuration Returns: ProcessInfo: process information
(self, script_config: ScriptConfig, run_time: Optional[int] = None)
| 426 | return conn |
| 427 | |
| 428 | def execute_script(self, script_config: ScriptConfig, run_time: Optional[int] = None) -> ProcessInfo: |
| 429 | """ |
| 430 | Execute a single script |
| 431 | |
| 432 | Args: |
| 433 | script_config: script configuration |
| 434 | run_time: run time (seconds), if None use script configuration |
| 435 | |
| 436 | Returns: |
| 437 | ProcessInfo: process information |
| 438 | """ |
| 439 | script_run_time = run_time or script_config.time_sec |
| 440 | |
| 441 | # Prepare execution environment |
| 442 | env = os.environ.copy() |
| 443 | env.update(script_config.environment) |
| 444 | |
| 445 | # Determine working directory |
| 446 | if script_config.cwd: |
| 447 | cwd = self.base_cwd / script_config.cwd |
| 448 | else: |
| 449 | cwd = self.base_cwd |
| 450 | |
| 451 | # Build command |
| 452 | cmd = [script_config.path] + script_config.args |
| 453 | |
| 454 | print(f"🚀 Execute script: {script_config.path}") |
| 455 | print(f" Working directory: {cwd}") |
| 456 | print(f" Run time: {script_run_time} seconds") |
| 457 | print(f" Environment variables: {script_config.environment}") |
| 458 | |
| 459 | if not self._is_remote(script_config): |
| 460 | try: |
| 461 | master_fd, slave_fd = pty.openpty() |
| 462 | process = subprocess.Popen( |
| 463 | cmd, |
| 464 | cwd=str(cwd), |
| 465 | env=env, |
| 466 | stdin=slave_fd, |
| 467 | stdout=slave_fd, |
| 468 | stderr=slave_fd, |
| 469 | close_fds=True |
| 470 | ) |
| 471 | try: |
| 472 | os.close(slave_fd) |
| 473 | except Exception: |
| 474 | pass |
| 475 | process_info = ProcessInfo( |
| 476 | script_path=script_config.path, |
| 477 | pid=process.pid, |
| 478 | process=process, |
| 479 | start_time=datetime.now(), |
| 480 | backend="local", |
| 481 | pty_master_fd=master_fd |
| 482 | ) |
| 483 | |
| 484 | with self._lock: |
| 485 | self._processes[script_config.path] = process_info |
no test coverage detected