summaryrefslogtreecommitdiff
path: root/docker/api/exec_api.py
diff options
context:
space:
mode:
Diffstat (limited to 'docker/api/exec_api.py')
-rw-r--r--docker/api/exec_api.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/docker/api/exec_api.py b/docker/api/exec_api.py
index 496308a..63df9e6 100644
--- a/docker/api/exec_api.py
+++ b/docker/api/exec_api.py
@@ -1,5 +1,6 @@
from .. import errors
from .. import utils
+from ..types import CancellableStream
class ExecApiMixin:
@@ -125,9 +126,10 @@ class ExecApiMixin:
detach (bool): If true, detach from the exec command.
Default: False
tty (bool): Allocate a pseudo-TTY. Default: False
- stream (bool): Stream response data. Default: False
+ stream (bool): Return response data progressively as an iterator
+ of strings, rather than a single string.
socket (bool): Return the connection socket to allow custom
- read/write operations.
+ read/write operations. Must be closed by the caller when done.
demux (bool): Return stdout and stderr separately
Returns:
@@ -161,7 +163,15 @@ class ExecApiMixin:
stream=True
)
if detach:
- return self._result(res)
+ try:
+ return self._result(res)
+ finally:
+ res.close()
if socket:
return self._get_raw_response_socket(res)
- return self._read_from_socket(res, stream, tty=tty, demux=demux)
+
+ output = self._read_from_socket(res, stream, tty=tty, demux=demux)
+ if stream:
+ return CancellableStream(output, res)
+ else:
+ return output