Redirects outputs and performs exec
(code: str, output_file, timeout_fyi: float, log: bool)
| 169 | |
| 170 | |
| 171 | def worker(code: str, output_file, timeout_fyi: float, log: bool): |
| 172 | "Redirects outputs and performs exec" |
| 173 | |
| 174 | # set up output redirection |
| 175 | c = worker_counter_box[0] |
| 176 | worker_counter_box[0] += 1 |
| 177 | stdouts: list = [output_file] |
| 178 | stderrs: list = [output_file] |
| 179 | if log: |
| 180 | stdouts.append(PrefixedFile(real_stdout, f"[python-exec-{c}]- ")) |
| 181 | stderrs.append(PrefixedFile(real_stderr, f"[python-exec-{c}]+ ")) |
| 182 | stdout.set_outputs(stdouts) |
| 183 | stderr.set_outputs(stderrs) |
| 184 | |
| 185 | # do the exec |
| 186 | try: |
| 187 | ipython_shell.run_cell(code) |
| 188 | except PythonExecTimeoutException: |
| 189 | print( |
| 190 | f"PythonExecTimeoutException: python exec timed out after {timeout_fyi} seconds", |
| 191 | file=stderr, |
| 192 | ) |
| 193 | except PythonExecOutOfMemoryException: |
| 194 | print( |
| 195 | "PythonExecOutOfMemoryException: python exec exceeded available memory. Python environment has been reset.", |
| 196 | file=stderr, |
| 197 | ) |
| 198 | except Exception as e: |
| 199 | traceback.print_exception(type(e), e, e.__traceback__, file=stderr) |
| 200 | |
| 201 | |
| 202 | def python_exec_sync( |
nothing calls this directly
no test coverage detected