|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import concurrent |
3 | 4 | import logging |
4 | 5 | import os |
5 | 6 | import platform |
@@ -222,6 +223,20 @@ def _get_docker_compose_commands_to_run( |
222 | 223 | return docker_compose_commands |
223 | 224 |
|
224 | 225 |
|
| 226 | +def _run_cmd(cmd: list[str], env: dict[str, str]) -> subprocess.CompletedProcess[str]: |
| 227 | + logger = logging.getLogger(LOGGER_NAME) |
| 228 | + try: |
| 229 | + logger.debug(f"Running command: {' '.join(cmd)}") |
| 230 | + return subprocess.run(cmd, check=True, capture_output=True, text=True, env=env) |
| 231 | + except subprocess.CalledProcessError as e: |
| 232 | + raise DockerComposeError( |
| 233 | + command=" ".join(cmd), |
| 234 | + returncode=e.returncode, |
| 235 | + stdout=e.stdout, |
| 236 | + stderr=e.stderr, |
| 237 | + ) from e |
| 238 | + |
| 239 | + |
225 | 240 | def run_docker_compose_command( |
226 | 241 | service: Service, |
227 | 242 | command: str, |
@@ -252,21 +267,13 @@ def run_docker_compose_command( |
252 | 267 | ) |
253 | 268 |
|
254 | 269 | cmd_outputs = [] |
255 | | - for cmd in docker_compose_commands: |
256 | | - try: |
257 | | - logger = logging.getLogger(LOGGER_NAME) |
258 | | - logger.debug(f"Running command: {' '.join(cmd)}") |
259 | | - cmd_outputs.append( |
260 | | - subprocess.run( |
261 | | - cmd, check=True, capture_output=True, text=True, env=current_env |
262 | | - ) |
263 | | - ) |
264 | | - except subprocess.CalledProcessError as e: |
265 | | - raise DockerComposeError( |
266 | | - command=command, |
267 | | - returncode=e.returncode, |
268 | | - stdout=e.stdout, |
269 | | - stderr=e.stderr, |
270 | | - ) from e |
| 270 | + |
| 271 | + with concurrent.futures.ThreadPoolExecutor() as executor: |
| 272 | + futures = [ |
| 273 | + executor.submit(_run_cmd, cmd, current_env) |
| 274 | + for cmd in docker_compose_commands |
| 275 | + ] |
| 276 | + for future in concurrent.futures.as_completed(futures): |
| 277 | + cmd_outputs.append(future.result()) |
271 | 278 |
|
272 | 279 | return cmd_outputs |
0 commit comments