Used to implement assert_python_*. *args are the command line flags to pass to the python interpreter. **env_vars keyword arguments are environment variables to set on the process. If __run_using_command= is supplied, it must be a list of command line arguments to prepend to the co
(*args, **env_vars)
| 94 | # Executing the interpreter in a subprocess |
| 95 | @support.requires_subprocess() |
| 96 | def run_python_until_end(*args, **env_vars): |
| 97 | """Used to implement assert_python_*. |
| 98 | |
| 99 | *args are the command line flags to pass to the python interpreter. |
| 100 | **env_vars keyword arguments are environment variables to set on the process. |
| 101 | |
| 102 | If __run_using_command= is supplied, it must be a list of |
| 103 | command line arguments to prepend to the command line used. |
| 104 | Useful when you want to run another command that should launch the |
| 105 | python interpreter via its own arguments. ["/bin/echo", "--"] for |
| 106 | example could print the unquoted python command line instead of |
| 107 | run it. |
| 108 | """ |
| 109 | env_required = interpreter_requires_environment() |
| 110 | run_using_command = env_vars.pop('__run_using_command', None) |
| 111 | cwd = env_vars.pop('__cwd', None) |
| 112 | if '__isolated' in env_vars: |
| 113 | isolated = env_vars.pop('__isolated') |
| 114 | else: |
| 115 | isolated = not env_vars and not env_required |
| 116 | cmd_line = [sys.executable, '-X', 'faulthandler'] |
| 117 | if run_using_command: |
| 118 | cmd_line = run_using_command + cmd_line |
| 119 | if isolated: |
| 120 | # isolated mode: ignore Python environment variables, ignore user |
| 121 | # site-packages, and don't add the current directory to sys.path |
| 122 | cmd_line.append('-I') |
| 123 | elif not env_vars and not env_required: |
| 124 | # ignore Python environment variables |
| 125 | cmd_line.append('-E') |
| 126 | |
| 127 | # But a special flag that can be set to override -- in this case, the |
| 128 | # caller is responsible to pass the full environment. |
| 129 | if env_vars.pop('__cleanenv', None): |
| 130 | env = {} |
| 131 | if sys.platform == 'win32': |
| 132 | # Windows requires at least the SYSTEMROOT environment variable to |
| 133 | # start Python. |
| 134 | env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] |
| 135 | |
| 136 | # Other interesting environment variables, not copied currently: |
| 137 | # COMSPEC, HOME, PATH, TEMP, TMPDIR, TMP. |
| 138 | else: |
| 139 | # Need to preserve the original environment, for in-place testing of |
| 140 | # shared library builds. |
| 141 | env = os.environ.copy() |
| 142 | |
| 143 | # set TERM='' unless the TERM environment variable is passed explicitly |
| 144 | # see issues #11390 and #18300 |
| 145 | if 'TERM' not in env_vars: |
| 146 | env['TERM'] = '' |
| 147 | |
| 148 | env.update(env_vars) |
| 149 | cmd_line.extend(args) |
| 150 | proc = subprocess.Popen(cmd_line, stdin=subprocess.PIPE, |
| 151 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 152 | env=env, cwd=cwd) |
| 153 | with proc: |
searching dependent graphs…