MCPcopy Create free account
hub / github.com/ActiveState/code / pyrun

Function pyrun

recipes/Python/580672_Register_exit_function/recipe-580672.py:158–173  ·  view source on GitHub ↗

Run python code 'src' in a separate interpreter. Return subprocess exit code.

(src)

Source from the content-addressed store, hash-verified

156 test_files = []
157
158 def pyrun(src):
159 """Run python code 'src' in a separate interpreter.
160 Return subprocess exit code.
161 """
162 if PY3:
163 src = bytes(src, 'ascii')
164 with tempfile.NamedTemporaryFile(suffix='.py', delete=False) as f:
165 f.write(src)
166 f.flush()
167 test_files.append(f.name)
168 code = subprocess.call(
169 [sys.executable, f.name],
170 stdout=None, stderr=None,
171 # creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
172 )
173 return code
174
175 def safe_remove(file):
176 "Convenience function for removing temporary test files"

Callers 12

test_exit_cleanlyMethod · 0.85
test_exceptionMethod · 0.85
test_signalMethod · 0.85
test_appended_signalMethod · 0.85
test_kinterruptMethod · 0.85
test_systemexitMethod · 0.85
test_called_onceMethod · 0.85
test_cascadeMethod · 0.85
test_all_exit_sigsMethod · 0.85
test_as_decoMethod · 0.85
test_err_in_funMethod · 0.85

Calls 5

bytesFunction · 0.85
writeMethod · 0.45
flushMethod · 0.45
appendMethod · 0.45
callMethod · 0.45

Tested by 12

test_exit_cleanlyMethod · 0.68
test_exceptionMethod · 0.68
test_signalMethod · 0.68
test_appended_signalMethod · 0.68
test_kinterruptMethod · 0.68
test_systemexitMethod · 0.68
test_called_onceMethod · 0.68
test_cascadeMethod · 0.68
test_all_exit_sigsMethod · 0.68
test_as_decoMethod · 0.68
test_err_in_funMethod · 0.68