cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ro...@apache.org
Subject [cloudstack] branch 4.11 updated: CLOUDSTACK-10243: Do not use wait() on Python subprocess (#2421)
Date Sat, 10 Feb 2018 17:27:03 GMT
This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.11
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.11 by this push:
     new ce67726  CLOUDSTACK-10243: Do not use wait() on Python subprocess (#2421)
ce67726 is described below

commit ce67726c6d3db6e7db537e76da6217c5d5f4b10e
Author: Wido den Hollander <wido@widodh.nl>
AuthorDate: Sat Feb 10 18:27:00 2018 +0100

    CLOUDSTACK-10243: Do not use wait() on Python subprocess (#2421)
    
    This might (and does block) in certain situations on the VR as
    also explained in the Python documentation:
    
    https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait
    
      Warning This will deadlock when using stdout=PIPE and/or stderr=PIPE
      and the child process generates enough output to a pipe such that
      it blocks waiting for the OS pipe buffer to accept more data.
      Use communicate() to avoid that.
    
    Using the check_output function handles most of this for us and
    also provides better error handling.
    
    Signed-off-by: Wido den Hollander <wido@widodh.nl>
---
 systemvm/debian/opt/cloud/bin/cs/CsHelper.py | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/systemvm/debian/opt/cloud/bin/cs/CsHelper.py b/systemvm/debian/opt/cloud/bin/cs/CsHelper.py
index 5397038..241643d 100755
--- a/systemvm/debian/opt/cloud/bin/cs/CsHelper.py
+++ b/systemvm/debian/opt/cloud/bin/cs/CsHelper.py
@@ -183,13 +183,19 @@ def get_hostname():
 
 def execute(command):
     """ Execute command """
-    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
-    p.wait()
-    rc = p.returncode
-
-    logging.debug("Executed: %s - exitstatus=%s " % (command, rc))
-    result = p.communicate()[0]
-    return result.splitlines()
+    returncode = -1
+    try:
+        logging.info("Executing: %s" % command)
+        result = subprocess.check_output(command, shell=True)
+        returncode = 0
+        return result.splitlines()
+    except subprocess.CalledProcessError as e:
+        logging.error(e)
+        returncode = e.returncode
+    finally:
+        logging.debug("Executed: %s - exitstatus=%s " % (command, returncode))
+
+    return list()
 
 
 def save_iptables(command, iptables_file):

-- 
To stop receiving notification emails like this one, please contact
rohit@apache.org.

Mime
View raw message