How to use in realtime the output generated by a python script

83 views
Skip to first unread message

Mirco Piccin

unread,
Apr 5, 2018, 10:16:33 AM4/5/18
to Node-RED
Hi everybody,
I've tried to run a python script that generates an output every 5 seconds (you can find it a the end of the message).
I've tried to run this script using nodered pythonshell, but it happens that the payload doesn't flow to the debug node until the end of the execution.

Is it possible to create a flow that allows to use every output generated by the scripts without waiting for the end of the execution?
I wasn't able to find any related post....

Can you help me?
Thanks everybody
Mirco


PS_
Example of the second python script:

from time import sleep
index = 0

print "Start "

while index < 5:
        print index
        index += 1
        sleep(5)
 

Example of the flow:
[{"id":"e0de42b1.049bd","type":"pythonshell in","z":"d8d38e5e.da6b2","name":"Continuous","pyfile":"/tmp/continuous.py","virtualenv":"","continuous":false,"x":331.5,"y":154,"wires":[["d1731e41.3f451"]]}]



Dave C-J

unread,
Apr 5, 2018, 10:35:37 AM4/5/18
to node...@googlegroups.com
If you use the built in exec node it says in the info

I don't know how you do that with that node - maybe need to contact the author direct...

Mirco Piccin

unread,
Apr 6, 2018, 5:00:11 AM4/6/18
to Node-RED
Hi Dave,
thanks for the tip!
Now it's working like a charm! 

Here the updated flow:
[{"id":"d1731e41.3f451","type":"debug","z":"d8d38e5e.da6b2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":790,"y":220,"wires":[]},{"id":"f6620ca7.7b73","type":"exec","z":"d8d38e5e.da6b2","command":"python -u /tmp/continuous.py","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"","x":450,"y":340,"wires":[["d1731e41.3f451"],[],[]]},{"id":"94002ba2.6dd0a8","type":"inject","z":"d8d38e5e.da6b2","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["f6620ca7.7b73"]]}]

thanks again
Mirco
Reply all
Reply to author
Forward
0 new messages