Skip to content

Commit 0ac1f9d

Browse files
committed
add threading to docker compose run
1 parent 9da0c84 commit 0ac1f9d

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

devservices/utils/docker_compose.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import concurrent
34
import logging
45
import os
56
import platform
@@ -222,6 +223,20 @@ def _get_docker_compose_commands_to_run(
222223
return docker_compose_commands
223224

224225

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+
225240
def run_docker_compose_command(
226241
service: Service,
227242
command: str,
@@ -252,21 +267,13 @@ def run_docker_compose_command(
252267
)
253268

254269
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())
271278

272279
return cmd_outputs

0 commit comments

Comments
 (0)