Commit 3563d18a authored by Jérome Perrin's avatar Jérome Perrin Committed by Julien Muchembled

standalone: unset PYTHONPATH at startup

In our normal operations, we are not using PYTHONPATH but using buildout
to generate wrappers. We are still using python setup.py test to run
tests, which sets PYTHONPATH to the eggs used by this python and this
cause issues when this python starts subprocesses, especially when it
starts another version of python which is supposed to use a different
set of eggs.
parent eb79c7e6
......@@ -643,7 +643,11 @@ class StandaloneSlapOS(object):
debug_args = prog.get('debug_args', '') # pylint: disable=unused-variable
command = prog['command'].format(**locals())
try:
return subprocess.check_call(command, shell=True)
return subprocess.check_call(
command,
shell=True,
env=self._getSubprocessEnvironment(),
)
except subprocess.CalledProcessError as e:
if e.returncode == SLAPGRID_PROMISE_FAIL:
self._logger.exception('Promise error when running %s', command)
......@@ -706,6 +710,7 @@ class StandaloneSlapOS(object):
output = subprocess.check_output(
['supervisord', '--configuration', self._supervisor_config],
cwd=self._base_directory,
env=self._getSubprocessEnvironment(),
)
self._logger.debug("Started new supervisor: %s", output)
......@@ -736,3 +741,14 @@ class StandaloneSlapOS(object):
return
time.sleep(i * .01)
raise RuntimeError("SlapOS not started")
def _getSubprocessEnvironment(self):
# Running tests with `python setup.py test` sets a PYTHONPATH that
# is suitable for current python, but problematic when this process
# runs another version of python in subprocess.
if 'PYTHONPATH' in os.environ:
self._logger.warning(
"Removing $PYTHONPATH from environment for subprocess")
env = os.environ.copy()
del env['PYTHONPATH']
return env
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment