{"record":{"id":"6d137da2530f905f","repo":"apache/seatunnel","slug":"timed-out-after-seconds-while-writing-python-sc","errorCode":null,"errorMessage":"Timed out after {} seconds while writing python.script.config; ensure the Python script reads its first stdin line","messagePattern":"Timed out after (.+?) seconds while writing python\\.script\\.config; ensure the Python script reads its first stdin line","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":354,"sourceCode":"                        \"python-source-stdin-writer\");\n        stdinWriterThread.setDaemon(true);\n        stdinWriterThread.start();\n    }\n\n    /** Fails process initialization when the child does not consume the initial JSON contract. */\n    private void waitForInitialConfigWrite() throws IOException {\n        try {\n            stdinWriterThread.join(TimeUnit.SECONDS.toMillis(INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS));\n        } catch (InterruptedException e) {\n            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    }","sourceCodeStart":336,"sourceCodeEnd":372,"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#L336-L372","documentation":"The Java↔Python contract requires the Python script to read its first stdin line, which carries python.script.config as JSON. If the child process does not consume that line within INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS, the write cannot complete and the reader throws this IOException at open().","triggerScenarios":"A Python script that never reads stdin (or reads it late — e.g. sleeps or imports heavy modules first), a script that blocks before its first stdin read, or a pipe buffering deadlock, causing waitForInitialConfigWrite to time out.","commonSituations":"Using a generic script not written against the SeaTunnel Python source contract; script has an interactive prompt or long startup; script was edited and the stdin read removed; wrong interpreter startup scripts delay main().","solutions":["Make the Python script read its first stdin line at startup (e.g. json.loads(sys.stdin.readline())) before doing other work","Verify the script is the intended contract-compliant entrypoint","Test the script locally: echo '{...}' | python script.py should not block","Check script startup time against the configured timeout"],"exampleFix":"# before\nimport time\ntime.sleep(60)\nconfig = json.loads(sys.stdin.readline())\n# after\nconfig = json.loads(sys.stdin.readline())  # read contract line first","handlingStrategy":"validation","validationCode":"# contract check: script must read first stdin line immediately\necho '{}' | timeout 5 python your_script.py || echo 'script violates stdin contract'","typeGuard":null,"tryCatchPattern":"try {\n    reader.open();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Timed out\")) {\n        // script did not read stdin; fix script before retrying\n    }\n}","preventionTips":["Always read sys.stdin.readline() as the first action in the script","Avoid sleeps, prompts, or heavy imports before the stdin read","Test the script standalone with piped stdin before deploying"],"tags":["process","ipc","timeout","python"],"backgroundTag":"request-timeout","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"}