@@ -13,34 +13,33 @@ def execute(cmds, quiet=True):
1313 content = ''
1414 stdouts = None
1515 start = time .time ()
16- with subprocess .Popen (cmds [0 ], stdout = subprocess .PIPE , shell = True ) as p :
17- # logging.debug('the current sub process pid(cwd: %s, ppid: %s, id: %s%d).' %
16+ p = subprocess .Popen (cmds [0 ], stdout = subprocess .PIPE , shell = True )
17+ # logging.debug('the current sub process pid(cwd: %s, ppid: %s, id: %s%d).' %
18+ # (p.pid, os.getppid(), type(p), id(p)))
19+ processes = [p ]
20+ for x in cmds [1 :]:
21+ #
22+ # the airticle link reference:
23+ #
24+ # 1. https://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate
25+ # 2. https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
26+ # 3. https://stackoverflow.com/questions/58649679/resourcewarning-unclosed-file-io-bufferedreader-name-4
27+ # 4. https://python.readthedocs.io/en/stable/library/subprocess.html
28+ #
29+ p = subprocess .Popen (x , stdin = p .stdout , stdout = subprocess .PIPE , bufsize = 1024 , shell = True )
30+ # logging.debug(
31+ # 'the current sub process pid(cwd: %s, ppid: %s, id: %s%d).' %
32+ # (p.pid, os.getppid(), type(p), id(p)))
33+ # logging.debug(type(p), id(p))
34+ processes .append (p )
35+ # logging.debug('the current run process pid(cwd: %s, ppid: %s, id: %s%d).' %
1836 # (p.pid, os.getppid(), type(p), id(p)))
19- processes = [p ]
20- for x in cmds [1 :]:
21- #
22- # the airticle link reference:
23- #
24- # 1. https://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate
25- # 2. https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
26- # 3. https://stackoverflow.com/questions/58649679/resourcewarning-unclosed-file-io-bufferedreader-name-4
27- # 4. https://python.readthedocs.io/en/stable/library/subprocess.html
28- #
29- p = subprocess .Popen (x , stdin = p .stdout , stdout = subprocess .PIPE , bufsize = 1024 , shell = True )
30- # logging.debug(
31- # 'the current sub process pid(cwd: %s, ppid: %s, id: %s%d).' %
32- # (p.pid, os.getppid(), type(p), id(p)))
33- # logging.debug(type(p), id(p))
34- processes .append (p )
35- # logging.debug('the current run process pid(cwd: %s, ppid: %s, id: %s%d).' %
36- # (p.pid, os.getppid(), type(p), id(p)))
37- # logging.debug(type(p), id(p))
38- stdouts , stderrs = p .communicate ()
39- if stderrs :
40- logging .error (stderrs )
41- for p in processes :
42- p .kill ()
43- p .wait ()
37+ # logging.debug(type(p), id(p))
38+ stdouts , stderrs = p .communicate ()
39+ if stderrs :
40+ logging .error (stderrs )
41+ for p in processes :
42+ p .wait ()
4443
4544 end = time .time ()
4645 if not quiet :
0 commit comments