Bug 818366 - Ability to pass through file descriptors to child processes; r=jhammel

This commit is contained in:
Gregory Szorc 2012-12-05 14:22:58 -08:00
parent 047d37efb9
commit 76c6d0c01e
2 changed files with 20 additions and 8 deletions

View File

@ -43,7 +43,7 @@ class ProcessExecutionMixin(LoggingMixin):
def run_process(self, args=None, cwd=None, append_env=None,
explicit_env=None, log_name=None, log_level=logging.INFO,
line_handler=None, require_unix_environment=False,
ensure_exit_code=0, ignore_children=False):
ensure_exit_code=0, ignore_children=False, pass_thru=False):
"""Runs a single process to completion.
Takes a list of arguments to run where the first item is the
@ -65,6 +65,13 @@ class ProcessExecutionMixin(LoggingMixin):
what is expected. If it is an integer, we raise an Exception if the
exit code does not match this value. If it is True, we ensure the exit
code is 0. If it is False, we don't perform any exit code validation.
pass_thru is a special execution mode where the child process inherits
this process's standard file handles (stdin, stdout, stderr) as well as
additional file descriptors. It should be used for interactive processes
where buffering from mozprocess could be an issue. pass_thru does not
use mozprocess. Therefore, arguments like log_name, line_handler,
and ignore_children have no effect.
"""
args = self._normalize_command(args, require_unix_environment)
@ -94,12 +101,15 @@ class ProcessExecutionMixin(LoggingMixin):
self.log(logging.DEBUG, 'process', {'env': use_env}, 'Environment: {env}')
p = ProcessHandlerMixin(args, cwd=cwd, env=use_env,
processOutputLine=[handleLine], universal_newlines=True,
ignore_children=ignore_children)
p.run()
p.processOutput()
status = p.wait()
if pass_thru:
status = subprocess.call(args, cwd=cwd, env=use_env)
else:
p = ProcessHandlerMixin(args, cwd=cwd, env=use_env,
processOutputLine=[handleLine], universal_newlines=True,
ignore_children=ignore_children)
p.run()
p.processOutput()
status = p.wait()
if ensure_exit_code is False:
return status

View File

@ -122,7 +122,8 @@ class MozbuildObject(ProcessExecutionMixin):
def _run_make(self, directory=None, filename=None, target=None, log=True,
srcdir=False, allow_parallel=True, line_handler=None,
append_env=None, explicit_env=None, ignore_errors=False,
ensure_exit_code=0, silent=True, print_directory=True):
ensure_exit_code=0, silent=True, print_directory=True,
pass_thru=False):
"""Invoke make.
directory -- Relative directory to look for Makefile in.
@ -179,6 +180,7 @@ class MozbuildObject(ProcessExecutionMixin):
'log_level': logging.INFO,
'require_unix_environment': True,
'ensure_exit_code': ensure_exit_code,
'pass_thru': pass_thru,
# Make manages its children, so mozprocess doesn't need to bother.
# Having mozprocess manage children can also have side-effects when