473,545 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: How to kill Python interpreter from the command line?


Thanks for the replies.

On May 8, 5:50*pm, Jean-Paul Calderone <exar...@divmod .comwrote:
Ctrl+C often works with Python, but as with any language, it's possible
to write a program which will not respond to it. *You can use Ctrl+\
instead (Ctrl+C sends SIGINT which can be masked or otherwise ignored,
Ctrl+\ sends SIGQUIT which typically isn't)
Yes, thank you, this seems to work. :)

I did some more testing and found out that the problem seems to be
thread-related. If I have a single-threaded program, then Ctrl+C
usually works, but if I have threads, it is usually ignored. For
instance, the below program does not respond to Ctrl+C (but it does
die when issued Ctrl+\):

import threading

def loop():
while True:
pass

threading.Threa d(target=loop,a rgs=()).start()
Jun 27 '08 #1
1 2007
On May 9, 11:19*am, spectru...@gmai l.com wrote:
Thanks for the replies.

On May 8, 5:50*pm, Jean-Paul Calderone <exar...@divmod .comwrote:
Ctrl+C often works with Python, but as with any language, it's possible
to write a program which will not respond to it. *You can use Ctrl+\
instead (Ctrl+C sends SIGINT which can be masked or otherwise ignored,
Ctrl+\ sends SIGQUIT which typically isn't)

Yes, thank you, this seems to work. :)

I did some more testing and found out that the problem seems to be
thread-related. If I have a single-threaded program, then Ctrl+C
usually works, but if I have threads, it is usually ignored. For
instance, the below program does not respond to Ctrl+C (but it does
die when issued Ctrl+\):

import threading

def loop():
* while True:
* * pass

threading.Threa d(target=loop,a rgs=()).start()
Your thread needs to be daemonised for this work. Othewise your main
thread will be waiting for your created thread to finish. E.g.:

thread = threading.Threa d(target=loop)
thread.setDaemo n(True)
thread.start()

But now it will exit immediately as soon as your main thread has
nothing to do anymore (which is right after .start() in this case), so
plug in another infinite loop at the end of this:

while True:
time.sleep(10)

And now your threaded app will stop when using C-c.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4936
by: leroybt.rm | last post by:
I don't understand why this does not work: <FILE1> test1.py #Import Packages import string # data=0 data=data+1
0
1985
by: vincent Salaun | last post by:
hi all, here's my problem : I've embedded a python interpreter in our java application (based on the NetBeans palteforrm) using the Jython API : http://www.jython.org/docs/javadoc/index.html So, i've used the PythonInterpreter class to instanciate an interpreter and to integrate it but the its environnement doesn't seem to be the
75
4605
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the functions are simplified versions of the full featured methods for compiled regular expressions. Most non-trivial applications always use the compiled...
4
2462
by: presentt | last post by:
Hello, I'm running Ubuntu Linux 5.04. I just started teaching myself Python today, and have been reading a few things to get started. I came across something in one (namely http://docs.python.org/tut/node4.html#SECTION004220000000000000000) that confused me a little. It says:
0
1194
by: Simon Eves | last post by:
I am trying to write a Python module to embed the functionality of Maya (the 3D modelling and animation application from Autodesk, formerly Alias) for doing scripted scene manipulation and rendering processes in Python. I am aware of the CGKit project, which does this and a lot more, but it is over-complex for our needs, and also does not...
0
1493
by: ycollet | last post by:
Hello, I'm trying to write a program to send python statements to a python server via tcp and then get back results via a tcp connection. It nearly works ... but I'm totally lost with the embedded dictionary (I'm quite new to python). The first part of the server start the python interpreter via Py_Initialize() and then waits for python...
48
2680
by: Yves Dorfsman | last post by:
On UNIX, some people use #!/usr/bin/env python While other use #!/usr/bin/python Why is one preferred over the other one ? Thanks.
3
5907
by: spectrumdt | last post by:
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...
2
1474
by: Peng Yu | last post by:
Hi, Perl has a command line help perldoc. I'm wondering if python has a similar help command. Thanks, Peng
0
7502
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7434
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.