Exec node issue

2,545 views
Skip to first unread message

Toshi Bass

unread,
Aug 7, 2017, 6:16:55 AM8/7/17
to Node-RED
1.) I have a exec node which starts a python script when I activate the node the script runs fine and I get a blue spot with say pid: 29478 
however if I check the process number with ps -A | grep python the pid number is actually 29482 not 29478 is this a bug or am I missing something ?

2.) Assuming the pid number worked on the node correctly would sending kill to that same node kill the process ? obviously at the moment it doesn't but if I send kill 29482 it works.

  

Dave C-J

unread,
Aug 7, 2017, 7:51:44 AM8/7/17
to node...@googlegroups.com
Interesting. Is there a process at 29478? If so what is it ? (What platform /os is this on)

sent from phone

Toshi Bass

unread,
Aug 7, 2017, 10:15:35 AM8/7/17
to Node-RED
No ...  there's no other python processes running 

the process..

pi@raspberrypi2:/ $ ps -A | grep python
pi@raspberrypi2:/ $
inject sudo ./ssd_1.py into the exec node  blue blob says pid:16789 and the process is running I get nothing on the exec nodes outputs
pi@raspberrypi2:/ $ ps -A | grep python
16793 ?        00:00:01 python2.7
pi@raspberrypi2:/ $ sudo kill 16793       
on exec node yellow blob says rc:143

(tried both exec and spawn mode with and without "Use old style output (compatibility mode)"! )

I assume sending "kill" to the exec node should end the process but using spawn mode and if I have "Use old style output (compatibility mode)"!  I get a yellow blob rc:1 but the process is still running. without "Use old ..." I get error 2

So sending kill does not appear to work and i don't get why there's a difference between the process pid in linux and the pid in node-red.

After further checking I find that if I make a separate exec node with "sudo kill 16789" or 16793 deploy and activate this it does kill the process but obviously that's not a practical solution. 

Any ideas ?

Raspberry pi b+  

pi@raspberrypi2:/ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian

7 Aug 13:15:55 - [info] Node-RED version: v0.17.5
7 Aug 13:15:55 - [info] Node.js  version: v6.11.2
7 Aug 13:15:55 - [info] Linux 4.4.50-v7+ arm LE
7 Aug 13:15:58 - [info] Loading palette nodes
7 Aug 13:16:07 - [info] Dashboard version 2.4.3 started at /ui




Nick O'Leary

unread,
Aug 7, 2017, 10:25:59 AM8/7/17
to Node-RED Mailing List
It might not be a python process... check for any process with that ID.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/aed7be6d-b084-4be1-8ed9-725380f18276%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Toshi Bass

unread,
Aug 7, 2017, 11:04:02 AM8/7/17
to Node-RED
hmmm checked that, result......

 9926 ?        00:00:00 sudo                 (9926 is the pid number on the exec node)
 9930 ?        00:00:23 python2.7         (9930 is the script that's running in python)

err now more confused....


Nick O'Leary

unread,
Aug 7, 2017, 11:11:48 AM8/7/17
to Node-RED Mailing List
what is the parent id of the python process?

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Toshi Bass

unread,
Aug 7, 2017, 1:31:21 PM8/7/17
to Node-RED

Sorry I don't understand, in reality its a stand alone python script that I am trying to start and stop, it imports paho.mqtt.client and Adafruit_SSD1306 libraries and it will enable me to send mqtt messages to ssd1306 display.

Your question what is the parent id did however give me an idea which was successful, I wrote a ssh script which starts and stops the script as a service, I get a brief flash of the pid on the node when the service is started and stopped followed by a yellow blob confirming the command was successful, but more importantly and get some msg.payloads confirmation on the output of the node see attached which is fine. 




Capture.JPG

Dave C-J

unread,
Aug 7, 2017, 3:23:02 PM8/7/17
to node...@googlegroups.com
If the script is running as sudo then it will fire up the python as a child process of the sudo session. Normally killing the parent should also kill the child process so stopping the pid displayed ought to kill the underlying script. If not then either try changing the signal passed to the process ( SIGKILL, SIGINT etc). Or maybe we need to investigate further. 
--
Sent from phone.

Toshi Bass

unread,
Aug 8, 2017, 6:03:28 AM8/8/17
to Node-RED

So even though this subject is solved for me by running my python script as a service.

I went back to the original flow to see if I could kill the process with SIGKILL, SIGINT, SIGQUIT, SIGHU, SIGTERM none worked then bearing in mind what you said about "running as sudo then it will fire up the python as a child process of the sudo session" which now makes sence to me ..  I found I could actually run the script without sudo (this was a surprise because I cannot run this script without sudo from the console or from another python script using a subprocess call) 

So for example now without using sudo the pid on the node says pid:6270 and if I run ps -A i get ...

 6270 ?        00:00:00 sh
 6271 ?        00:00:00 python2.7

I could not kill the process with any combination of commands as listed above including kill which really should work, I guess kill is trying to kill 6270 which is still not the pid of my running script.

Dave C-J

unread,
Aug 8, 2017, 7:21:34 AM8/8/17
to node...@googlegroups.com
Well the python process "should" be a child process of the sh one. So killing the sh should kill the python. But what exactly is in the exec node ? 

sent from phone

Toshi Bass

unread,
Aug 8, 2017, 10:20:25 AM8/8/17
to Node-RED
For sure killing 6270 the sh process does not kill the python process even if I use the console pi@raspberrypi2:/ $ sudo kill 6270 or sending kill 6270 to a exec node only thing that works is   kill 6271

Attached is what I have in the exec node basically nothing but I have tried all combinations of spawn mode and old style SIGKILL ... etc, none of them successfully kills the python process
Capture.JPG
Capture.JPG

Dave C-J

unread,
Aug 9, 2017, 4:41:21 PM8/9/17
to node...@googlegroups.com
If I use
Inline images 1
Then I can kill it no problem...

which version of Node-RED are you using ?

Toshi Bass

unread,
Aug 10, 2017, 5:30:29 AM8/10/17
to Node-RED
7 Aug 13:15:55 - [info] Node-RED version: v0.17.5
7 Aug 13:15:55 - [info] Node.js version: v6.11.2
7 Aug 13:15:55 - [info] Linux 4.4.50-v7+ arm LE
7 Aug 13:15:58 - [info] Loading palette nodes
7 Aug 13:16:07 - [info] Dashboard version 2.4.3 started at /ui

so what are you sending to kill the script once you have started it, I tried the above method to start the script but still I cannot kill it.

Nick O'Leary

unread,
Aug 10, 2017, 6:14:15 AM8/10/17
to Node-RED Mailing List
Toshi - are you running node-red under sudo?

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Toshi Bass

unread,
Aug 10, 2017, 6:49:37 AM8/10/17
to Node-RED

Nope I installed as follows :

node-red-stop
sudo apt-get remove nodered
sudo apt-get remove nodejs nodejs-legacy
sudo apt-get remove npm

sudo apt-get install build-essential python-rpi.gpio


sudo apt-get update && sudo apt-get install python-rpi.gpio

Added auto start, initiated it with sudo systemctl enable nodered.service  then if I want to stop and start it without rebooting I use node-red-stop and node-red-start

All additional nodes were installed without sudo in  cd ~/.node-red


Dave C-J

unread,
Aug 10, 2017, 9:07:02 AM8/10/17
to node...@googlegroups.com
Toshi

this is my flow

[{"id":"efed3ace.2700c8","type":"inject","z":"b1f28b1.0c4c378","name":"start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":110,"y":660,"wires":[["6e5a066d.6ffdf8"]]},{"id":"c43baeb5.2fcf8","type":"debug","z":"b1f28b1.0c4c378","name":"","active":true,"console":"false","complete":"true","x":470,"y":680,"wires":[]},{"id":"6e5a066d.6ffdf8","type":"exec","z":"b1f28b1.0c4c378","command":"python","addpay":false,"append":"-u /tmp/sleep.py","useSpawn":"true","timer":"","oldrc":false,"name":"","x":270,"y":720,"wires":[["c43baeb5.2fcf8"],["4b9b94f8.76fe6c"],["8dd4bc61.240c1"]]},{"id":"4b9b94f8.76fe6c","type":"debug","z":"b1f28b1.0c4c378","name":"","active":true,"console":"false","complete":"true","x":470,"y":720,"wires":[]},{"id":"8dd4bc61.240c1","type":"debug","z":"b1f28b1.0c4c378","name":"","active":true,"console":"false","complete":"true","x":470,"y":760,"wires":[]},{"id":"4b75f6e2.3e07c8","type":"inject","z":"b1f28b1.0c4c378","name":"kill","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":110,"y":780,"wires":[["ed92df1c.d25eb"]]},{"id":"ed92df1c.d25eb","type":"function","z":"b1f28b1.0c4c378","name":"","func":"msg.kill = true;\nreturn msg;","outputs":1,"noerr":0,"x":130,"y":720,"wires":[["6e5a066d.6ffdf8"]]}]


and the sleep.py is

#! /usr/bin/python
import time
while True:
    print("This prints every 10 secs.")
    time.sleep(10)   # Delay for 1 minute (60 seconds).

Toshi Bass

unread,
Aug 10, 2017, 1:15:17 PM8/10/17
to Node-RED
Aha that function node with :

msg.kill = true;
return msg;

solves the kill problem, although I do have a problem with your flow in that the directory tmp is not accessible, I guess it has something to do with permissions (currently its rwxr-xr-x  pi) or I need a sym-link, but it doesn't matter as my file ssd_1.py is in /home/pi and having  -u ./ssd_1.py in the exec works fine, as does -u ./sleep.py  

Thanks for your example I hope it help someone else who maybe has the same same problem.

Heinz Oberlechner

unread,
Jan 14, 2018, 2:10:09 PM1/14/18
to Node-RED
I had the same problem. The solution of the problem for me was change the output of the exec node from "exec-mode" to "spawn-mode"!

Jan Van den Audenaerde

unread,
Apr 18, 2018, 3:28:26 AM4/18/18
to Node-RED

I also had the same problem and same solution as mentioned by "Heinz Oberlechner" fixed it.
So I had to change "exec-mode"  into "spawn-mode".
Maybe some extra node documentation highlighting the difference between killing in spawn or in exec mode would be interesting.

FYI
The exec command I am using
mplayer -volume 20 http://progressive-audio.lwc.vrtcdn.be/content/fixed/11_11niws-snip_hi.mp3"

my fixed flow is :

[{"id":"d9ccf5e4.c1c8e8","type":"tab","label":"radio news","disabled":false,"info":""},{"id":"718493b4.8e71ac","type":"exec","z":"d9ccf5e4.c1c8e8","command":"mplayer -volume 20 http://progressive-audio.lwc.vrtcdn.be/content/fixed/11_11niws-snip_hi.mp3","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"vrt news","x":447,"y":164,"wires":[["4ffff3d1.342bec"],["c1cd2df6.30193"],["869048d.ba116b8"]]},{"id":"d1b9d456.fee6e8","type":"comment","z":"d9ccf5e4.c1c8e8","name":"comments","info":"https://www.vrt.be/nl/aanbod/kijk-en-luister/radio-luisteren/streamingslinks-radio/\n\nmplayer -volume 20 http://progressive-audio.lwc.vrtcdn.be/content/fixed/11_11niws-snip_hi.mp3\n\nTodo : killing doesn't work.\n\n","x":239,"y":58,"wires":[]},{"id":"f56470b9.3ad02","type":"inject","z":"d9ccf5e4.c1c8e8","name":"start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":141,"y":153,"wires":[["718493b4.8e71ac"]]},{"id":"d0060488.308368","type":"inject","z":"d9ccf5e4.c1c8e8","name":"stop","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":138,"y":244,"wires":[["b9364dd6.afcc6"]]},{"id":"4ffff3d1.342bec","type":"debug","z":"d9ccf5e4.c1c8e8","name":"stdout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":113,"wires":[]},{"id":"c1cd2df6.30193","type":"debug","z":"d9ccf5e4.c1c8e8","name":"stderr","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":629,"y":149,"wires":[]},{"id":"869048d.ba116b8","type":"debug","z":"d9ccf5e4.c1c8e8","name":"return code","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":653,"y":190,"wires":[]},{"id":"b9364dd6.afcc6","type":"change","z":"d9ccf5e4.c1c8e8","name":"msg.kill = SIGINT","rules":[{"t":"set","p":"kill","pt":"msg","to":"SIGINT","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":314,"y":243,"wires":[["718493b4.8e71ac"]]}]



Dave C-J

unread,
Apr 18, 2018, 3:42:36 AM4/18/18
to node...@googlegroups.com
Doc PRs always welcome.

Jan Van den Audenaerde

unread,
Apr 18, 2018, 4:00:05 AM4/18/18
to Node-RED
OK Dave :-). 
Recently learning Git & Github - so when I am up to speed with Git and Github I will give that try.

On Wednesday, April 18, 2018 at 9:42:36 AM UTC+2, Dave C-J wrote:
Doc PRs always welcome.

Dave C-J

unread,
Apr 18, 2018, 9:39:35 AM4/18/18
to node...@googlegroups.com
Always going to encourage you to learn...
but if you have some simple suggested words - cut/paste can also work :-)
Reply all
Reply to author
Forward
0 new messages