Skip to content

Commit 4ff2962

Browse files
committed
Merge branch 'funkyfuture-container_exec_run'
2 parents 5728eeb + 947c47f commit 4ff2962

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

docker/models/containers.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
from collections import namedtuple
23

34
from ..api import APIClient
45
from ..errors import (ContainerError, ImageNotFound,
@@ -150,9 +151,10 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
150151
workdir (str): Path to working directory for this exec session
151152
152153
Returns:
153-
(tuple): A tuple of (exit_code, output)
154+
(ExecResult): A tuple of (exit_code, output)
154155
exit_code: (int):
155-
Exit code for the executed command
156+
Exit code for the executed command or ``None`` if
157+
either ``stream```or ``socket`` is ``True``.
156158
output: (generator or str):
157159
If ``stream=True``, a generator yielding response chunks.
158160
If ``socket=True``, a socket object for the connection.
@@ -170,10 +172,13 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
170172
exec_output = self.client.api.exec_start(
171173
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
172174
)
173-
exit_code = 0
174-
if stream is False:
175-
exit_code = self.client.api.exec_inspect(resp['Id'])['ExitCode']
176-
return (exit_code, exec_output)
175+
if socket or stream:
176+
return ExecResult(None, exec_output)
177+
178+
return ExecResult(
179+
self.client.api.exec_inspect(resp['Id'])['ExitCode'],
180+
exec_output
181+
)
177182

178183
def export(self):
179184
"""
@@ -1004,3 +1009,8 @@ def _host_volume_from_bind(bind):
10041009
return bits[0]
10051010
else:
10061011
return bits[1]
1012+
1013+
1014+
ExecResult = namedtuple('ExecResult', 'exit_code,output')
1015+
""" A result of Container.exec_run with the properties ``exit_code`` and
1016+
``output``. """

0 commit comments

Comments
 (0)