MCPcopy Create free account
hub / github.com/FastMAS/KVCOMM / _runner

Function _runner

KVCOMM/tools/coding/python_executor.py:45–58  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

43def execute_code_get_return(code: str, timeout: int = 5):
44 """在子进程执行 code,超过 timeout 秒直接终止,并返回 answer 变量(或错误信息)。"""
45 def _runner(q):
46 local_vars = {}
47 try:
48
49 exec(textwrap.dedent(code), {}, local_vars)
50 res = local_vars.get("answer")
51
52 if callable(res):
53 res = res()
54
55 q.put(res)
56 except Exception:
57
58 q.put(f"Error occurred:\n{traceback.format_exc()}")
59
60 q = mp.Queue()
61 p = mp.Process(target=_runner, args=(q,))

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected