(timeoutMs: number)
| 5 | /** Local subprocess execution, not a security sandbox. Requires python3 and pandas. */ |
| 6 | export 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 | }); |
no outgoing calls
no test coverage detected