Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   KeyboardInterrupt being lost? (http://www.velocityreviews.com/forums/t350319-keyboardinterrupt-being-lost.html)

Operation Latte Thunder 10-14-2005 08:27 PM

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

David Wahler 10-14-2005 09:18 PM

Re: KeyboardInterrupt being lost?
 
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



All times are GMT. The time now is 07:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.