{"record":{"id":"75127878574ff1b7","repo":"apache/seatunnel","slug":"python-script-exited-before-reading-its-first-stdi","errorCode":null,"errorMessage":"Python script exited before reading its first stdin line; python.script.config could not be delivered{}","messagePattern":"Python script exited before reading its first stdin line; python\\.script\\.config could not be delivered(.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-python/src/main/java/org/apache/seatunnel/connectors/seatunnel/python/source/PythonSourceReader.java","lineNumber":364,"sourceCode":"            Thread.currentThread().interrupt();\n            throw new IOException(\"Interrupted while writing python.script.config\", e);\n        }\n\n        if (closeRequested) {\n            throw new IOException(\"Python source was closed while writing python.script.config\");\n        }\n        if (!initialConfigWritten) {\n            throw new IOException(\n                    \"Timed out after \"\n                            + INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS\n                            + \" seconds while writing python.script.config; ensure the Python script reads its first stdin line\");\n        }\n        if (stdinWriterFailure != null) {\n            if (!process.isAlive()) {\n                // A closed stdin pipe surfaces here as a generic write IOException (e.g. \"Broken\n                // pipe\"), but the actual contract violation is that the script exited without\n                // reading python.script.config; report that instead of the write symptom.\n                throw new IOException(\n                        \"Python script exited before reading its first stdin line;\"\n                                + \" python.script.config could not be delivered\"\n                                + formatRecentStderr(),\n                        stdinWriterFailure);\n            }\n            throw new IOException(\"Failed to write python.script.config\", stdinWriterFailure);\n        }\n    }\n\n    /** The first stdin line is the stable contract between Java and the Python script. */\n    private void writeInitialScriptConfig(Map<String, Object> scriptConfig) throws IOException {\n        try (BufferedWriter writer =\n                new BufferedWriter(\n                        new OutputStreamWriter(\n                                process.getOutputStream(), StandardCharsets.UTF_8))) {\n            writer.write(JsonUtils.toJsonString(scriptConfig));\n            writer.newLine();\n            writer.flush();","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-python/src/main/java/org/apache/seatunnel/connectors/seatunnel/python/source/PythonSourceReader.java#L346-L382","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the attached child stderr in the exception message for the real error","Run the Python script manually with the same interpreter to reproduce the crash","Install missing Python dependencies for the configured python.executable","Verify the script path and interpreter are valid in the execution environment"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"python -c \"import your_script\"  # catches syntax errors / missing modules before job run","typeGuard":null,"tryCatchPattern":"try {\n    reader.open();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"exited before reading its first stdin line\")) {\n        log.error(\"Python child crashed: {}\", e.getMessage()); // stderr is embedded\n    }\n}","preventionTips":["Pre-verify the script runs with the exact configured interpreter","Install all Python dependencies in the execution environment","Keep the script's stderr clean of noise so real errors are visible"],"tags":["process","broken-pipe","python","startup"],"backgroundTag":"broken-pipe","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}