473,396 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

KeyboardInterrupt being lost?

I have a simple test proggie that isn't behaving like I expect ( found
below ). The script will infinitely run ( as expected ), but seems to
completely ignore control-C's. Shouldn't the interpreter pass along
KeyboardInterrupts and break out of the while loop, or am I missing
something?

Using python 2.4.2 on linux ( if it matters )

-- Script Below --

import threading, traceback, time

class TestThread ( threading.Thread ):
def __init__ ( self ):
threading.Thread.__init__ ( self )
def run ( self ):
print "Starting..."
while True:
time.sleep ( 1 )
return

if __name__ == '__main__':
test = TestThread ( )
test.start()
print "Started..."
test.join()
--
chris
Oct 14 '05 #1
1 2288
Operation Latte Thunder wrote:
I have a simple test proggie that isn't behaving like I expect ( found
below ). The script will infinitely run ( as expected ), but seems to
completely ignore control-C's. Shouldn't the interpreter pass along
KeyboardInterrupts and break out of the while loop, or am I missing
something?

Using python 2.4.2 on linux ( if it matters )

-- Script Below --

import threading, traceback, time

class TestThread ( threading.Thread ):
def __init__ ( self ):
threading.Thread.__init__ ( self )
def run ( self ):
print "Starting..."
while True:
time.sleep ( 1 )
return

if __name__ == '__main__':
test = TestThread ( )
test.start()
print "Started..."
test.join()
--
chris


Chris,

Thread.join() is implemented using a lock, and the acquisition of a
lock is uninterruptible. (See
http://docs.python.org/lib/module-thread.html) Therefore, your main
thread will block until the other thread terminates or the process is
forcibly killed. Even if it could be interrupted, I don't think there's
any way to raise that exception in the other thread. (Python's
threading support leaves something to be desired when compared to, say,
Java.)

-- David

Oct 14 '05 #2

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

Similar topics

2
by: Steve Holden | last post by:
I'm mailing the list in the hope that somebody has come up with a solution to the occasional spurious "Keyboard Interrupt" exception that gets raised in the ASP environment. It's a little awkward...
8
by: Ivan Nestlerode | last post by:
Hello comp.lang.python, I am attempting to write a threaded program right now in Python (version 2.3 on Debian unstable) and the current behavior of KeyboardInterrupt is causing me grief. From...
0
by: PantherSE | last post by:
Hello, Ok, here's my situation. I have a small application that listens to messages on a UDP port. When I pass None to settimeout(), and I hit Ctrl+C to interrupt the wait my exception...
4
by: Tamas Nepusz | last post by:
Hi everyone, I have tried to do some googling before asking my question here, but I haven't found any suitable answer. I am developing a Python API for a graph library written in pure C. The...
1
by: darren kirby | last post by:
Hello all. I have a python script here which is just a wrapper for 2 or more system commands. I would estimate the program spends at least 95.5% of 'real' time running the system commands. ...
4
by: Tony Nelson | last post by:
I'm trying to find out what is eating some KeyboardInterrupt exceptions in a fairly large program (yum). My KeyboardInterrupt handler is called for some Ctl-C presses, but for others nothing seems...
6
by: ruka_at_ | last post by:
Hi, why is KeyboardInterrupt not caught (xp)? import sys try: inp = sys.stdin.read() except (KeyboardInterrupt, SystemExit): print "kbd-interr,SystemExit" except EOFError: print "eof...
2
by: Michael Goerz | last post by:
Hi, when I try to catch ctrl+c with except KeyboardInterrupt: pychecker tells me Catching a non-Exception object (KeyboardInterrupt)
1
by: radim.marek | last post by:
Hi Guys, during testing of my project on FreeBSD I've discovered stange 'feature' of time.sleep(). It works if single thread is running, but when multi-threaded, the SIGINT signal seems not to...
7
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.