1 """@namespace IMP.parallel.subproc Subprocess handling."""
11 class _Popen4(subprocess.Popen):
13 """Utility class to provide a portable way to spawn a child process and
14 communicate with its stdin and combined stdout/stderr."""
16 def __init__(self, cmd):
18 shell = (sys.platform !=
"win32")
19 subprocess.Popen.__init__(
20 self, cmd, shell=shell, stdin=subprocess.PIPE,
21 stdout=subprocess.PIPE,
22 stderr=subprocess.STDOUT)
24 def require_clean_exit(self):
25 """Make sure the child exited with a zero return code"""
28 raise IOError(
"Process failed with exit status %d" % r)
30 if sys.platform ==
'win32':
31 def _run_background(cmdline, out):
32 """Run a process in the background and direct its output to a file"""
33 print "%s > %s" % (cmdline, out)
37 p = subprocess.Popen(cmdline, shell=
False, stdout=open(out,
'w'),
38 stderr=subprocess.STDOUT)
41 except WindowsError, detail:
42 print(
"WindowsError: %s (ignored)" % detail)
46 def _run_background(cmdline, out):
47 """Run a process in the background and direct its output to a file"""
48 print "%s > %s" % (cmdline, out)
49 subprocess.Popen(cmdline, shell=
True, stdout=open(out,
'w'),
50 stderr=subprocess.STDOUT)
See IMP.parallel for more information.