Skip to content

Commit

Permalink
Merge pull request #18 from Autodesk/subprocess_environment
Browse files Browse the repository at this point in the history
Subprocess jobs inherit parent environment
  • Loading branch information
avirshup authored Sep 27, 2017
2 parents 247ec38 + 9b38780 commit a5128ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyccc/engines/subproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ def submit(self, job):
for filename, f in job.inputs.items():
f.put(os.path.join(job.workingdir, filename))

subenv = os.environ.copy()
subenv['PYTHONIOENCODING'] = 'utf-8'
job.subproc = subprocess.Popen(job.command,
shell=True,
cwd=job.workingdir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={'PYTHONIOENCODING': 'utf-8'})
env=subenv)
job.jobid = job.subproc.pid
job._started = True
return job.subproc.pid
Expand Down
15 changes: 15 additions & 0 deletions pyccc/tests/test_job_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ def test_bash_exitcode(fixture, request):
assert job.exitcode == 35


@pytest.fixture
def set_env_var():
import os
assert 'NULL123' not in os.environ, "Bleeding environment"
os.environ['NULL123'] = 'nullabc'
yield
del os.environ['NULL123']


def test_subprocess_environment_preserved(subprocess_engine, set_env_var):
job = subprocess_engine.launch(command='echo $NULL123', image='python:2.7-slim')
job.wait()
assert job.stdout.strip() == 'nullabc'


@pytest.mark.parametrize('fixture', fixture_types['engine'])
def test_python_exitcode(fixture, request):
engine = request.getfuncargvalue(fixture)
Expand Down

0 comments on commit a5128ea

Please sign in to comment.