Closed FrederikPM closed 2 months ago
Thank you @FrederikPM ! Thanks also for adding Eslint and Prettier. I have never used these tools, so it may take me some time to check the code.
I have checked that if it is not in continuous mode, this node runs as before.
If continuous mode is set, a new input to the node terminates the already running Python process and starts it again.
When I press the button on the node, it stops executing and when I press it again, it starts from the beginning.
If msg.terminate is true, the process is terminated, and if false, the process is executed again.
If "Continuously running script terminated" is displayed, pressing the button on the node executes the script again, but if it is not displayed, pressing the button does not execute the script.
Is this the expected behavior? Below is the flow of checking the behavior of continuous mode.
Good catch! Here is a python script with a while loop for the continuous mode:
[{ "id": "25441caf3c8534e2", "type": "venv", "z": "7a7ae303f662be9f", "venvconfig": "4657b6fbdbaf6f7e", "name": "venv test", "code": "# Import the time library\nimport time\nstart = time.time()\n\noffset = msg[\"payload\"] if \"payload\" in msg else 0\n\ntime.sleep(1)\nend = time.time()\nlength = end - start\nprint(f'Time: {length}')\n\nwhile True:\n time.sleep(1)\n end = time.time()\n length = end - start\n print(f'Time: {length + offset}')", "continuous": true, "stdInData": false, "x": 380, "y": 180, "wires": [ [ "114b918e3eb7ad96" ] ] }, { "id": "446c4d54c3afdb80", "type": "inject", "z": "7a7ae303f662be9f", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "5", "payloadType": "num", "x": 110, "y": 220, "wires": [ [ "25441caf3c8534e2" ] ] }, { "id": "5056f4320a8479d0", "type": "inject", "z": "7a7ae303f662be9f", "name": "terminate", "props": [ { "p": "terminate", "v": "true", "vt": "bool" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 120, "y": 140, "wires": [ [ "25441caf3c8534e2" ] ] }, { "id": "114b918e3eb7ad96", "type": "debug", "z": "7a7ae303f662be9f", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 640, "y": 180, "wires": [] }, { "id": "4657b6fbdbaf6f7e", "type": "venv-config", "venvname": "pyenv", "version": "default" }]
In regards to eslint and prettier it was simply to have a concise coding style for the project when using vscode. Feel free to change the rules as you see fit (can be done in .prettierrc) :)
Thank you @FrederikPM ! I have checked that a python script with a while loop works in continuous mode. I will add a sample flow later.
I have also checked that the code can be formatted with Prettier. I have been concerned about unifying the writing style, so I will use it!
I merge this Pull Request. If you see any behavior that you do not expect, please feel free to submit a Pull Request.
Implemented a continuous mode inspired by the feature found in the pythonshell node
However, this continuous mode supports being triggered not only by the button on the node but also by any input to the node. Thus, if continuous mode is enabled, the following applies: