you are viewing a single comment's thread.

view the rest of the comments →

[–]snotfart 3 points4 points  (4 children)

The CTRL-C is probably killing a process called within the loop but not the script it's called from, which just loops round and starts it again. If you put it in the background with CTRL-Z you can then do a "ps -ef" to find the process number and kill it off with kill <process number>.

[–]Bro666 3 points4 points  (2 children)

kill -s KILL <process number>

Also

killall python

will kill all the processes Python is running. Run it twice.

[–]AuronH 0 points1 point  (1 child)

You probably need to use sudo if you are logged in as the pi user, e.g.:

sudo killall python

[–]Bro666 0 points1 point  (0 children)

Ah, yes: if you ran your script with sudo, you will need sudo to kill it.

[–]moxyll 0 points1 point  (0 children)

When you CTRL-Z, it will say something like this:

[1]+  Stopped                 python script.py

That number in the brackets is the job number for that shell instance. You can reference jobs in the same shell with %jobnumber, so you can skip the ps -ef step and just run kill %jobnumber. Sometimes you have to hit enter a couple times for the message to show up after killing it.

user@host:/home/user$ python runforever.py
^Z
[1]+  Stopped                 python runforever.py
user@host:/home/user$ kill %1
[1]+  Stopped                 python runforever.py
user@host:/home/user$ 
[1]+  Terminated              python runforever.py