Commit 9571d48a authored by Jérome Perrin's avatar Jérome Perrin

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): ...@@ -643,7 +643,11 @@ class StandaloneSlapOS(object):
debug_args = prog.get('debug_args', '') # pylint: disable=unused-variable debug_args = prog.get('debug_args', '') # pylint: disable=unused-variable
command = prog['command'].format(**locals()) command = prog['command'].format(**locals())
try: try:
return subprocess.check_call(command, shell=True) return subprocess.check_call(
command,
shell=True,
env=self._getSubprocessEnvironment(),
)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
if e.returncode == SLAPGRID_PROMISE_FAIL: if e.returncode == SLAPGRID_PROMISE_FAIL:
self._logger.exception('Promise error when running %s', command) self._logger.exception('Promise error when running %s', command)
...@@ -706,6 +710,7 @@ class StandaloneSlapOS(object): ...@@ -706,6 +710,7 @@ class StandaloneSlapOS(object):
output = subprocess.check_output( output = subprocess.check_output(
['supervisord', '--configuration', self._supervisor_config], ['supervisord', '--configuration', self._supervisor_config],
cwd=self._base_directory, cwd=self._base_directory,
env=self._getSubprocessEnvironment(),
) )
self._logger.debug("Started new supervisor: %s", output) self._logger.debug("Started new supervisor: %s", output)
...@@ -736,3 +741,12 @@ class StandaloneSlapOS(object): ...@@ -736,3 +741,12 @@ class StandaloneSlapOS(object):
return return
time.sleep(i * .01) time.sleep(i * .01)
raise RuntimeError("SlapOS not started") 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")
return {k:v for k, v in os.environ.items() if k != 'PYTHONPATH'}
return None
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