404background / node-red-contrib-python-venv

Node for python virtual environment
https://flows.nodered.org/node/@background404/node-red-contrib-python-venv
MIT License
10 stars 4 forks source link

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

Closed Alkarex closed 4 months ago

Alkarex commented 4 months ago

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 ```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 commented 4 months ago

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.