Skip to content

Use spawn instead of exec to support larger output payloads#7

Merged
404background merged 3 commits into404background:mainfrom
Alkarex:spawn
Jun 26, 2024
Merged

Use spawn instead of exec to support larger output payloads#7
404background merged 3 commits into404background:mainfrom
Alkarex:spawn

Conversation

@Alkarex
Copy link
Contributor

@Alkarex Alkarex commented Jun 26, 2024

Fix for Error: spawnSync /bin/sh ENOBUFS when the data returned by the Python script is too large.

Inspired by https://stackoverflow.com/questions/63796633/spawnsync-bin-sh-enobufs

Test Python script:

def generate_large_string():
	large_string = 'A' * 5000000
	return large_string

result = generate_large_string()
print(result)

Test JavaScript function;

msg.payload = msg.payload.length;
return msg;
flows.json
[
    {
        "id": "f14c248431d474e8",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 260,
        "wires": [
            [
                "8be43bb7c337f2b3"
            ]
        ]
    },
    {
        "id": "b50cd141069d9975",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 260,
        "wires": []
    },
    {
        "id": "8be43bb7c337f2b3",
        "type": "venv",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "code": "def generate_large_string():\n\tlarge_string = 'A' * 5000000\n\treturn large_string\n\nresult = generate_large_string()\nprint(result)\n",
        "x": 350,
        "y": 260,
        "wires": [
            [
                "9dcaea21518426b1"
            ]
        ]
    },
    {
        "id": "9dcaea21518426b1",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "function 1",
        "func": "msg.payload = msg.payload.length;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 540,
        "y": 260,
        "wires": [
            [
                "b50cd141069d9975"
            ]
        ]
    }
]

@404background
Copy link
Owner

Thank you @Alkarex !
I read your code and tried the flow.

Before your modification, I got an error.
スクリーンショット 2024-06-26 234555

With your code, I can run it without any problem!
スクリーンショット 2024-06-26 232403

I think it is fine, so I merge this pull request.

@404background 404background merged commit 3e8e286 into 404background:main Jun 26, 2024
@Alkarex Alkarex deleted the spawn branch June 26, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants