| 293 | raise TimeoutError(f"Server did not start within {timeout_seconds} seconds") |
| 294 | |
| 295 | def stop(self) -> None: |
| 296 | if self.external_server: |
| 297 | print("[external_server]: Not stopping external server") |
| 298 | return |
| 299 | if self in server_instances: |
| 300 | server_instances.remove(self) |
| 301 | if self.process: |
| 302 | print(f"Stopping server with pid={self.process.pid}") |
| 303 | self.process.terminate() |
| 304 | try: |
| 305 | self.process.wait(timeout=5) |
| 306 | except subprocess.TimeoutExpired: |
| 307 | print(f"Server pid={self.process.pid} did not terminate in time, killing") |
| 308 | self.process.kill() |
| 309 | self.process.wait(timeout=5) |
| 310 | except Exception as e: |
| 311 | print(f"Error waiting for server: {e}") |
| 312 | self.process = None |
| 313 | if hasattr(self, '_log') and self._log != sys.stdout: |
| 314 | self._log.close() |
| 315 | |
| 316 | def make_request( |
| 317 | self, |