In a Docker container on Ubuntu, I'm running a .sh file which calls python3 my_script_file.py. In that file, I do:
commands = []
commands.append("export OMP_NUM_THREADS=4")
commands.append("echo $OMP_NUM_THREADS")
I then execute the commands array with:
def execute_commands_list(commands, no_bash_script = False):
for command in commands:
if not no_bash_script and gc.output_to_bash_script:
write_command_to_bash_script(command)
else:
print(" [ " + command + " ]")
ret = subprocess.call(command, shell=True, executable="/bin/bash")
assert ret==0 or ret==2, "bash return code error: " + str(ret) + " " + command
Here is the output:
[ export OMP_NUM_THREADS=4 ]
[ echo $OMP_NUM_THREADS ]
(that's a blank line). I try running echo $OMP_NUM_THREADS in the terminal after execution myself, and get nothing. If I run those both commands manually however the env var is set.
(I have also tried os.environ, and that has failed as well)
What am I missing?
(For reference, the .sh file is:)
#!/bin/bash -p
python3 my_script_file.py