()
| 368 | } |
| 369 | |
| 370 | private async start(): Promise<void> { |
| 371 | const rustHostPath = await resolvePythonReplHostExecutable() |
| 372 | const child = rustHostPath |
| 373 | ? spawn(rustHostPath, [], { |
| 374 | cwd: process.cwd(), |
| 375 | env: { |
| 376 | ...process.env, |
| 377 | }, |
| 378 | stdio: ['pipe', 'pipe', 'pipe'], |
| 379 | }) |
| 380 | : spawn(resolvePythonExecutable(), [kernelAssetPath], { |
| 381 | cwd: process.cwd(), |
| 382 | env: { |
| 383 | ...process.env, |
| 384 | NCODE_PY_TMP_DIR: tmpdir(), |
| 385 | NCODE_PY_REPL_PYTHON_MODULE_DIRS: '', |
| 386 | }, |
| 387 | stdio: ['pipe', 'pipe', 'pipe'], |
| 388 | }) |
| 389 | |
| 390 | child.stdout.setEncoding('utf8') |
| 391 | child.stderr.setEncoding('utf8') |
| 392 | |
| 393 | const stdoutReader = createInterface({ |
| 394 | input: child.stdout, |
| 395 | crlfDelay: Infinity, |
| 396 | }) |
| 397 | stdoutReader.on('line', line => { |
| 398 | void this.handleKernelStdoutLine(line) |
| 399 | }) |
| 400 | |
| 401 | child.stderr.on('data', chunk => { |
| 402 | const text = String(chunk) |
| 403 | for (const line of text.split('\n')) { |
| 404 | const trimmed = line.trim() |
| 405 | if (!trimmed) continue |
| 406 | this.stderrTail.push(trimmed) |
| 407 | if (this.stderrTail.length > 20) { |
| 408 | this.stderrTail.shift() |
| 409 | } |
| 410 | } |
| 411 | }) |
| 412 | |
| 413 | const handleExit = (reason: string) => { |
| 414 | this.shutdown(reason) |
| 415 | } |
| 416 | child.on('error', error => { |
| 417 | handleExit(error.message) |
| 418 | }) |
| 419 | child.on('exit', (code, signal) => { |
| 420 | handleExit( |
| 421 | `Python REPL kernel exited${code !== null ? ` with code ${code}` : ''}${signal ? ` (${signal})` : ''}`, |
| 422 | ) |
| 423 | }) |
| 424 | |
| 425 | this.child = child |
| 426 | this.stdoutReader = stdoutReader |
| 427 | } |
no test coverage detected