qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Silbe <silbe@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org, Fam Zheng <famz@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] docker.py: don't hang on large docker output
Date: Thu, 18 Aug 2016 22:12:30 +0200	[thread overview]
Message-ID: <1471551152-26107-2-git-send-email-silbe@linux.vnet.ibm.com> (raw)
In-Reply-To: <1471551152-26107-1-git-send-email-silbe@linux.vnet.ibm.com>

Unlike Popen.communicate(), subprocess.call() doesn't read from the
stdout file descriptor. If the child process produces more output than
fits into the pipe buffer, it will block indefinitely.

If we don't intend to consume the output, just send it straight to
/dev/null to avoid this issue.

Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
---
This fixes a hang for me when building the Ubuntu docker image (empty
docker image cache).

 tests/docker/docker.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 222a105..efb2bf4 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -25,6 +25,10 @@ from tarfile import TarFile, TarInfo
 from StringIO import StringIO
 from shutil import copy, rmtree
 
+
+DEVNULL = open(os.devnull, 'wb')
+
+
 def _text_checksum(text):
     """Calculate a digest string unique to the text content"""
     return hashlib.sha1(text).hexdigest()
@@ -34,8 +38,7 @@ def _guess_docker_command():
     commands = [["docker"], ["sudo", "-n", "docker"]]
     for cmd in commands:
         if subprocess.call(cmd + ["images"],
-                           stdout=subprocess.PIPE,
-                           stderr=subprocess.PIPE) == 0:
+                           stdout=DEVNULL, stderr=DEVNULL) == 0:
             return cmd
     commands_txt = "\n".join(["  " + " ".join(x) for x in commands])
     raise Exception("Cannot find working docker command. Tried:\n%s" % \
@@ -98,7 +101,7 @@ class Docker(object):
 
     def _do(self, cmd, quiet=True, infile=None, **kwargs):
         if quiet:
-            kwargs["stdout"] = subprocess.PIPE
+            kwargs["stdout"] = DEVNULL
         if infile:
             kwargs["stdin"] = infile
         return subprocess.call(self._command + cmd, **kwargs)
-- 
1.9.1

  reply	other threads:[~2016-08-18 20:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 20:12 [Qemu-devel] [PATCH 0/3] docker tests fixes Sascha Silbe
2016-08-18 20:12 ` Sascha Silbe [this message]
2016-08-19  8:58   ` [Qemu-devel] [PATCH 1/3] docker.py: don't hang on large docker output Janosch Frank
2016-08-18 20:12 ` [Qemu-devel] [PATCH 2/3] docker: avoid dependency on 'realpath' package Sascha Silbe
2016-08-18 20:12 ` [Qemu-devel] [PATCH 3/3] docker: debian-bootstrap.pre: print helpful message if DEB_ARCH/DEB_TYPE unset Sascha Silbe
2016-08-19  9:56 ` [Qemu-devel] [PATCH 0/3] docker tests fixes Alex Bennée
2016-08-23 13:52   ` Sascha Silbe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471551152-26107-2-git-send-email-silbe@linux.vnet.ibm.com \
    --to=silbe@linux.vnet.ibm.com \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).