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)
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)
26 if sys.platform ==
'win32':
27 def _run_background(cmdline, out):
28 """Run a process in the background and direct its output to a file"""
29 print "%s > %s" % (cmdline, out)
33 p = subprocess.Popen(cmdline, shell=
False, stdout=open(out,
'w'),
34 stderr=subprocess.STDOUT)
37 except WindowsError
as detail:
38 print(
"WindowsError: %s (ignored)" % detail)
42 def _run_background(cmdline, out):
43 """Run a process in the background and direct its output to a file"""
44 print "%s > %s" % (cmdline, out)
45 subprocess.Popen(cmdline, shell=
True, stdout=open(out,
'w'),
46 stderr=subprocess.STDOUT)