17

I wrote a python script but accidentally put an infinite while loop in my script.

How do I kill the process? I've tried ctrl+c but with no success.

Are there any other option to try?

I'm on Mac Os X 10.7.2 with python 2.7

Harpal
  • 12,057
  • 18
  • 61
  • 74

4 Answers4

33

Try Ctrl+\ to send a SIGQUIT.

wim
  • 338,267
  • 99
  • 616
  • 750
25

try this.

pkill -9 python

or

ps -ef|grep python
kill -9 <pid>

or

lsof -i :port

or 
sudo kill $(sudo lsof -t -i:8000)
Ranvijay Sachan
  • 2,407
  • 3
  • 30
  • 49
25

ps a to get the PID of your process. kill -9 <pid> to send it the unblockable SIGKILL signal.

Note that I only have a Linux box in front of me to test, so the OS X commands may be slightly different.

tdenniston
  • 3,389
  • 2
  • 21
  • 29
  • worked perfectly thanks. Out of curiosity what is the -9 flag for? – Harpal Nov 09 '11 at 14:25
  • 1
    `SIGKILL` is signal number 9. `kill -X` is shorthand for `kill -s SIGNAME` if you don't want to type the symbolic name, and you know the number. I believe if you do `kill -l` (that's a lowercase L) it will list the signals and numbers on your system. – tdenniston Nov 09 '11 at 14:27
1

Open Activity monitor, go to the Processes tab, and highlight python.exe and quit it by clicking Quit.

onetwopunch
  • 3,279
  • 2
  • 29
  • 44
  • this is maybe not the answer everyone likes, but it's still correct. You can use the activity monitor to kill it. – dwalter Sep 25 '20 at 18:15