Long ago, I submitted an issue: https://github.com/kimchi-project/kimchi/issues/1170 ...

Test by following script:

import subprocess
import os
import time

def _check_remote_libvirt_conn(remote_host,
        user='root', transport='ssh'):

    FNULL = open(os.devnull, 'w')
    dest_uri = 'qemu+%s://%s@%s/system' % (transport, user, remote_host)
    cmd = ['virsh', '-c', dest_uri, 'list']
    proc = subprocess.Popen(cmd, stdout=FNULL, stderr=FNULL,
            shell=True, preexec_fn=os.setsid)
    timeout = 0
    while proc.poll() is None:
        time.sleep(1)
        timeout += 1
        if timeout == 5:
            print("killed")
            os.killpg(os.getpgid(proc.pid), signal.SIGTERM)

if __name__ == '__main__':
    _check_remote_libvirt_conn('localhost')

`proc` is timeout every time although the connection is normal tested by `virsh -c <uri>` list


The following is the reason of changing(From Python Document 2.7.14):

 Do not use stdout=PIPE or stderr=PIPE with this function as that can deadlock based on the child process output volume. Use Popen with the communicate() method when you need pipes.

 Using shell=True can be a security hazard. See the warning under Frequently Used Arguments for details.

At the same time, if not change, it does not work.


diff --git a/model/vms.py b/model/vms.py
index 6da4f3b..92e771f 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -1885,10 +1885,11 @@ class VMModel(object):
     def _check_remote_libvirt_conn(self, remote_host,
                                    user='root', transport='ssh'):
 
+        FNULL = open(os.devnull, 'w')
         dest_uri = 'qemu+%s://%s@%s/system' % (transport, user, remote_host)
         cmd = ['virsh', '-c', dest_uri, 'list']
-        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                                shell=True, preexec_fn=os.setsid)
+        proc = subprocess.Popen(cmd, stdout=FNULL, stderr=FNULL,
+                                shell=False, preexec_fn=os.setsid)
         timeout = 0
         while proc.poll() is None:
             time.sleep(1)

-- 
Regards
River (Fu.Lin)