1 """@namespace IMP.parallel.subproc Subprocess handling."""
10 class _Popen4(subprocess.Popen):
11 """Utility class to provide a portable way to spawn a child process and
12 communicate with its stdin and combined stdout/stderr."""
14 def __init__(self, cmd):
16 shell = (sys.platform !=
"win32")
17 subprocess.Popen.__init__(self, cmd, shell=shell, stdin=subprocess.PIPE,
18 stdout=subprocess.PIPE,
19 stderr=subprocess.STDOUT)
21 def require_clean_exit(self):
22 """Make sure the child exited with a zero return code"""
25 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 p = subprocess.Popen(cmdline, shell=
False, stdout=open(out,
'w'),
35 stderr=subprocess.STDOUT)
38 except WindowsError, detail:
39 print(
"WindowsError: %s (ignored)" % detail)
43 def _run_background(cmdline, out):
44 """Run a process in the background and direct its output to a file"""
45 print "%s > %s" % (cmdline, out)
46 subprocess.Popen(cmdline, shell=
True, stdout=open(out,
'w'),
47 stderr=subprocess.STDOUT)
See IMP.parallel for more information.