From cb37e4b02334b56d24b3d3765c6e715bbe70fd89 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 6 Dec 2023 23:11:46 +0100 Subject: [PATCH] add env testing prototype --- prototyping/env_var_subprocess.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prototyping/env_var_subprocess.py diff --git a/prototyping/env_var_subprocess.py b/prototyping/env_var_subprocess.py new file mode 100644 index 0000000..aa0a027 --- /dev/null +++ b/prototyping/env_var_subprocess.py @@ -0,0 +1,17 @@ +import os +import subprocess + +# Set an environment variable in the parent process +os.environ["PARENT_VARIABLE"] = "12345s" + +# Spawn a subprocess and modify the environment variable +subprocess.run( + [ + "python", + "-c", + "import os; print('b', os.environ['PARENT_VARIABLE']); os.environ['PARENT_VARIABLE'] = 'modified_value'; print('c', os.environ['PARENT_VARIABLE'])", + ] +) + +# Check if the modification in the subprocess affected the parent process +print("a", os.environ["PARENT_VARIABLE"]) # This will print 'parent_value', not 'modified_value'