MCPcopy Create free account
hub / github.com/SamuelSchmidgall/AgentLaboratory / worker_run_code

Function worker_run_code

tools.py:292–304  ·  view source on GitHub ↗
(code_str, output_queue)

Source from the content-addressed store, hash-verified

290import matplotlib.pyplot as plt
291
292def worker_run_code(code_str, output_queue):
293 output_capture = io.StringIO()
294 sys.stdout = output_capture
295 try:
296 # Create a globals dictionary with __name__ set to "__main__"
297 globals_dict = {"__name__": "__main__"}
298 exec(code_str, globals_dict)
299 except Exception as e:
300 output_capture.write(f"[CODE EXECUTION ERROR]: {str(e)}\n")
301 traceback.print_exc(file=output_capture)
302 finally:
303 sys.stdout = sys.__stdout__
304 output_queue.put(output_capture.getvalue())
305
306def execute_code(code_str, timeout=600, MAX_LEN=1000):
307 #code_str = code_str.replace("\\n", "\n")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected