Run python code 'src' in a separate interpreter. Return subprocess exit code.
(src)
| 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" |