MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / run_code

Function run_code

utils/wei_utils.py:220–243  ·  view source on GitHub ↗

Execute Python code and capture stdout as well as the full stack trace on error. Forces __name__ = "__main__" so that if __name__ == "__main__": blocks will run. Returns: (output, error) - output: string containing everything that was printed to stdout - err

(code)

Source from the content-addressed store, hash-verified

218 return run_code(utils_functions + '\n' + code)
219
220def run_code(code):
221 """
222 Execute Python code and capture stdout as well as the full stack trace on error.
223 Forces __name__ = "__main__" so that if __name__ == "__main__": blocks will run.
224
225 Returns:
226 (output, error)
227 - output: string containing everything that was printed to stdout
228 - error: string containing the full traceback if an exception occurred; None otherwise
229 """
230 stdout_capture = io.StringIO()
231 # Provide a globals dict specifying that __name__ is "__main__"
232 exec_globals = {"__name__": "__main__"}
233
234 with contextlib.redirect_stdout(stdout_capture):
235 try:
236 exec(code, exec_globals)
237 error = None
238 except Exception:
239 # Capture the entire stack trace
240 error = traceback.format_exc()
241
242 output = stdout_capture.getvalue()
243 return output, error
244
245
246def run_code_from_agent(agent, msg, num_retries=1):

Callers 11

new_pipeline.pyFile · 0.90
run_code_with_utilsFunction · 0.85
run_code_from_agentFunction · 0.85
run_modularFunction · 0.85
fill_contentFunction · 0.85
gen_layoutFunction · 0.85
gen_layout_parallelFunction · 0.85
render_textboxFunction · 0.85
gen_outline_layoutFunction · 0.85
render_textboxFunction · 0.85
gen_outline_layoutFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected