apache/seatunnel · error · IOException

Python script exited before reading its first stdin line; py

Error message

Python script exited before reading its first stdin line; python.script.config could not be delivered{}

What it means

When the stdin writer fails (typically 'Broken pipe') because the Python child process already exited without reading the initial config line, the reader reports the root cause — premature exit — instead of the write symptom. It includes the most recent stderr from the child to explain why the script died.

Source

Thrown at seatunnel-connectors-v2/connector-python/src/main/java/org/apache/seatunnel/connectors/seatunnel/python/source/PythonSourceReader.java:364

            Thread.currentThread().interrupt();
            throw new IOException("Interrupted while writing python.script.config", e);
        }

        if (closeRequested) {
            throw new IOException("Python source was closed while writing python.script.config");
        }
        if (!initialConfigWritten) {
            throw new IOException(
                    "Timed out after "
                            + INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS
                            + " seconds while writing python.script.config; ensure the Python script reads its first stdin line");
        }
        if (stdinWriterFailure != null) {
            if (!process.isAlive()) {
                // A closed stdin pipe surfaces here as a generic write IOException (e.g. "Broken
                // pipe"), but the actual contract violation is that the script exited without
                // reading python.script.config; report that instead of the write symptom.
                throw new IOException(
                        "Python script exited before reading its first stdin line;"
                                + " python.script.config could not be delivered"
                                + formatRecentStderr(),
                        stdinWriterFailure);
            }
            throw new IOException("Failed to write python.script.config", stdinWriterFailure);
        }
    }

    /** The first stdin line is the stable contract between Java and the Python script. */
    private void writeInitialScriptConfig(Map<String, Object> scriptConfig) throws IOException {
        try (BufferedWriter writer =
                new BufferedWriter(
                        new OutputStreamWriter(
                                process.getOutputStream(), StandardCharsets.UTF_8))) {
            writer.write(JsonUtils.toJsonString(scriptConfig));
            writer.newLine();
            writer.flush();

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Read the attached child stderr in the exception message for the real error
  2. Run the Python script manually with the same interpreter to reproduce the crash
  3. Install missing Python dependencies for the configured python.executable
  4. Verify the script path and interpreter are valid in the execution environment
Defensive patterns

Strategy: try-catch

Validate before calling

python -c "import your_script"  # catches syntax errors / missing modules before job run

Try / catch

try {
    reader.open();
} catch (IOException e) {
    if (e.getMessage().contains("exited before reading its first stdin line")) {
        log.error("Python child crashed: {}", e.getMessage()); // stderr is embedded
    }
}

Prevention

When it happens

Trigger: The Python process crashes or exits immediately at startup (syntax error, missing module, bad path, non-zero exit) before consuming python.script.config from stdin; the subsequent stdin write fails and this IOException is thrown.

Common situations: python.executable missing packages (ModuleNotFoundError); script has a syntax error under the chosen interpreter; script path wrong so interpreter exits with 'can't open file'; container lacking a dependency.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/75127878574ff1b7. Report an issue: GitHub.