1 """@namespace IMP.parallel.subproc Subprocess handling."""
7 class _Popen4(subprocess.Popen):
9 """Utility class to provide a portable way to spawn a child process and
10 communicate with its stdin and combined stdout/stderr."""
12 def __init__(self, cmd):
14 shell = (sys.platform !=
"win32")
15 subprocess.Popen.__init__(
16 self, cmd, shell=shell, stdin=subprocess.PIPE,
17 stdout=subprocess.PIPE,
18 stderr=subprocess.STDOUT, universal_newlines=
True)
20 def require_clean_exit(self):
21 """Make sure the child exited with a zero return code"""
24 raise IOError(
"Process failed with exit status %d" % r)
27 if sys.platform ==
'win32':
28 def _run_background(cmdline, out):
29 """Run a process in the background and direct its output to a file"""
30 print(
"%s > %s" % (cmdline, out))
34 _ = subprocess.Popen(cmdline, shell=
False, stdout=open(out,
'w'),
35 stderr=subprocess.STDOUT,
36 universal_newlines=
True)
39 except WindowsError
as detail:
40 print((
"WindowsError: %s (ignored)" % detail))
44 def _run_background(cmdline, out):
45 """Run a process in the background and direct its output to a file"""
46 print(
"%s > %s" % (cmdline, out))
47 subprocess.Popen(cmdline, shell=
True, stdout=open(out,
'w'),
48 stderr=subprocess.STDOUT,
49 universal_newlines=
True)