MCPcopy Create free account
hub / github.com/antvis/AVA / createPythonExecutor

Function createPythonExecutor

src/interpreter/python/util/execute.ts:7–35  ·  view source on GitHub ↗
(timeoutMs: number)

Source from the content-addressed store, hash-verified

5/** Local subprocess execution, not a security sandbox. Requires python3 and pandas. */
6export const createPythonExecutor =
7 (timeoutMs: number) =>
8 (code: string, maxBuffer: number): Promise<ExecutionResult> =>
9 new Promise((resolve, reject) => {
10 const child = execFile(
11 'python3',
12 ['-'],
13 {
14 timeout: timeoutMs,
15 killSignal: 'SIGKILL',
16 maxBuffer,
17 encoding: 'utf8',
18 },
19 (error, stdout, stderr) => {
20 if (error) {
21 reject(
22 new Error(`Python execution failed (requires python3 and pandas): ${stderr.trim() || error.message}`)
23 );
24 return;
25 }
26 try {
27 resolve(JSON.parse(stdout));
28 } catch {
29 reject(new Error('Python returned an invalid JSON result'));
30 }
31 }
32 );
33 child.stdin!.on('error', reject);
34 child.stdin!.end(code);
35 });

Callers 4

constructorMethod · 0.90
validateDSLMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected