MCPcopy Index your code
hub / github.com/RustPython/RustPython / run_python_until_end

Function run_python_until_end

Lib/test/support/script_helper.py:95–159  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 6

get_child_detailsMethod · 0.90
strace_pythonFunction · 0.90
_assert_pythonFunction · 0.85

Calls 10

communicateMethod · 0.95
killMethod · 0.95
_PythonRunResultClass · 0.85
popMethod · 0.45
appendMethod · 0.45
copyMethod · 0.45
updateMethod · 0.45
extendMethod · 0.45
_cleanupMethod · 0.45