KeyboardInterrupt being lost?

Discussion in 'Python' started by Operation Latte Thunder, Oct 14, 2005.

  1. 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
    Operation Latte Thunder, Oct 14, 2005
    #1
    1. Advertising

  2. Operation Latte Thunder

    David Wahler Guest

    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
    David Wahler, Oct 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Holden

    ASP KeyboardInterrupt errors

    Steve Holden, Jun 24, 2003, in forum: Python
    Replies:
    2
    Views:
    727
    Mark Hammond
    Jun 28, 2003
  2. Ivan Nestlerode

    KeyboardInterrupt and threading

    Ivan Nestlerode, Jan 2, 2004, in forum: Python
    Replies:
    8
    Views:
    536
    Anand Pillai
    Jan 8, 2004
  3. PantherSE
    Replies:
    0
    Views:
    343
    PantherSE
    May 16, 2005
  4. Tamas Nepusz
    Replies:
    4
    Views:
    626
    Dieter Maurer
    Oct 22, 2005
  5. Jai
    Replies:
    1
    Views:
    167
    Neil Cerutti
    Nov 19, 2013
Loading...

Share This Page