By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,740 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,740 IT Pros & Developers. It's quick & easy.

How to kill Python interpreter from the command line?

P: n/a
Hello.

I am running Fedora Linux and KDE, using the Konsole command line.

When coding Python, I regularly make a bug causing my program to not
terminate. But how do I kill the non-terminating Python interpreter
without killing the entire Konsole?

The default way of killing the current process on the command line is
Ctrl+C, but that doesn't work with Python. Neither do the "terminate
task", "suspend task" or "interrupt task" commands (available from
right-click in Konsole).

So, can someone please help? How do I kill Python without having to
restart Konsole?

Thanks in advance.
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies

P: n/a
sp********@gmail.com wrote:
Hello.

I am running Fedora Linux and KDE, using the Konsole command line.

When coding Python, I regularly make a bug causing my program to not
terminate. But how do I kill the non-terminating Python interpreter
without killing the entire Konsole?

The default way of killing the current process on the command line is
Ctrl+C, but that doesn't work with Python. Neither do the "terminate
task", "suspend task" or "interrupt task" commands (available from
right-click in Konsole).

So, can someone please help? How do I kill Python without having to
restart Konsole?

put it into the background using C-z, and then look for it's pid using ps.
Issue a kill -9 towards it.

For example, I just in the moment use this commandline to do so (for a
certain script named frontend_cherrypy.py:

ps ux | grep frontend | kill -9 `cut -c 5-15`

Diez
Jun 27 '08 #2

P: n/a
sp********@gmail.com wrote:
The default way of killing the current process on the command line is
Ctrl+C, but that doesn't work with Python.
It should work.

Do you have a bare except: which intercepts SystemExit as well?

If so, be as specific as possible in what you intercept, or at least
catch StandardError:

In [1]: StandardError ?
Type: type
Base Class: <type 'type'>
String Form: <type 'exceptions.StandardError'>
Namespace: Python builtin
Docstring:
Base class for all standard Python exceptions that do not represent
interpreter exiting.
Jun 27 '08 #3

P: n/a
On 2008-05-08, sp********@gmail.com <sp********@gmail.comwrote:
I am running Fedora Linux and KDE, using the Konsole command line.
I also run python from Konsole.
When coding Python, I regularly make a bug causing my program to not
terminate. But how do I kill the non-terminating Python interpreter
without killing the entire Konsole?
Are you refering to the python editor? If so, try cntrl-d.
The default way of killing the current process on the command line is
Ctrl+C, but that doesn't work with Python. Neither do the "terminate
task", "suspend task" or "interrupt task" commands (available from
right-click in Konsole).
If you want to completely kill python, open another Konsole session and kill
it from there. There are several ways. The simplist is:

killall python

.....which will kill python without killing the Konsole session.

This will find the python pid number and kill it with -15 which cleans
everything up nicely before killing. If that doesn't work, you may need to
use kill -9, which is kill with extreme prejudice and leaves all the bodies
lying around to crap up the works. To do that, try:

ps aux | grep python

......which will give you the pid number and then you plug it into:

kill -9 pid_number

If all that doesn't work, change to Slackware! ;)

nb
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.