Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > KeyboardInterrupt being lost?

Reply
Thread Tools

KeyboardInterrupt being lost?

 
 
Operation Latte Thunder
Guest
Posts: n/a
 
      10-14-2005
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
 
Reply With Quote
 
 
 
 
David Wahler
Guest
Posts: n/a
 
      10-14-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
exception KeyboardInterrupt and os.system command darren kirby Python 1 11-27-2005 11:18 PM
KeyboardInterrupt vs extension written in C Tamas Nepusz Python 4 10-22-2005 08:02 PM
Socket object and KeyboardInterrupt exception PantherSE Python 0 05-16-2005 09:10 PM
KeyboardInterrupt and threading Ivan Nestlerode Python 8 01-08-2004 11:12 AM
ASP KeyboardInterrupt errors Steve Holden Python 2 06-28-2003 01:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57