Bug 1628838 - Fix mach python on Windows by unsetting PYTHONUNBUFFERED. r=glandium
The existence of this environment variable breaks the Python shell on Windows, so make sure it's unset (but only in this case to avoid regressing bug 1627873). Differential Revision: https://phabricator.services.mozilla.com/D70542
This commit is contained in:
@@ -42,10 +42,11 @@ if os.environ.get('MSYSTEM', None) in ('MINGW32', 'MINGW64'):
|
|||||||
class ProcessExecutionMixin(LoggingMixin):
|
class ProcessExecutionMixin(LoggingMixin):
|
||||||
"""Mix-in that provides process execution functionality."""
|
"""Mix-in that provides process execution functionality."""
|
||||||
|
|
||||||
def run_process(self, args=None, cwd=None, append_env=None,
|
def run_process(
|
||||||
explicit_env=None, log_name=None, log_level=logging.INFO,
|
self, args=None, cwd=None, append_env=None, explicit_env=None,
|
||||||
line_handler=None, require_unix_environment=False,
|
log_name=None, log_level=logging.INFO, line_handler=None,
|
||||||
ensure_exit_code=0, ignore_children=False, pass_thru=False):
|
require_unix_environment=False, ensure_exit_code=0,
|
||||||
|
ignore_children=False, pass_thru=False, python_unbuffered=True):
|
||||||
"""Runs a single process to completion.
|
"""Runs a single process to completion.
|
||||||
|
|
||||||
Takes a list of arguments to run where the first item is the
|
Takes a list of arguments to run where the first item is the
|
||||||
@@ -74,6 +75,13 @@ class ProcessExecutionMixin(LoggingMixin):
|
|||||||
where buffering from mozprocess could be an issue. pass_thru does not
|
where buffering from mozprocess could be an issue. pass_thru does not
|
||||||
use mozprocess. Therefore, arguments like log_name, line_handler,
|
use mozprocess. Therefore, arguments like log_name, line_handler,
|
||||||
and ignore_children have no effect.
|
and ignore_children have no effect.
|
||||||
|
|
||||||
|
When python_unbuffered is set, the PYTHONUNBUFFERED environment variable
|
||||||
|
will be set in the child process. This is normally advantageous (see bug
|
||||||
|
1627873) but is detrimental in certain circumstances (specifically, we
|
||||||
|
have seen issues when using pass_thru mode to open a Python subshell, as
|
||||||
|
in bug 1628838). This variable should be set to False to avoid bustage
|
||||||
|
in those circumstances.
|
||||||
"""
|
"""
|
||||||
args = self._normalize_command(args, require_unix_environment)
|
args = self._normalize_command(args, require_unix_environment)
|
||||||
|
|
||||||
@@ -101,7 +109,8 @@ class ProcessExecutionMixin(LoggingMixin):
|
|||||||
if append_env:
|
if append_env:
|
||||||
use_env.update(append_env)
|
use_env.update(append_env)
|
||||||
|
|
||||||
use_env['PYTHONUNBUFFERED'] = '1'
|
if python_unbuffered:
|
||||||
|
use_env['PYTHONUNBUFFERED'] = '1'
|
||||||
|
|
||||||
self.log(logging.DEBUG, 'process', {'env': use_env}, 'Environment: {env}')
|
self.log(logging.DEBUG, 'process', {'env': use_env}, 'Environment: {env}')
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class MachCommands(MachCommandBase):
|
|||||||
return self.run_process([python_path] + args,
|
return self.run_process([python_path] + args,
|
||||||
pass_thru=True, # Allow user to run Python interactively.
|
pass_thru=True, # Allow user to run Python interactively.
|
||||||
ensure_exit_code=False, # Don't throw on non-zero exit code.
|
ensure_exit_code=False, # Don't throw on non-zero exit code.
|
||||||
|
python_unbuffered=False, # Leave input buffered.
|
||||||
append_env=append_env)
|
append_env=append_env)
|
||||||
|
|
||||||
@Command('python-test', category='testing',
|
@Command('python-test', category='testing',
|
||||||
|
|||||||
Reference in New Issue
Block a user