Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion KeyboardInterrupt eats my error and then won't be caught
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
greg  
View profile  
 More options Jun 20 2009, 12:09 am
Newsgroups: comp.lang.python
From: greg <g...@cosc.canterbury.ac.nz>
Date: Sat, 20 Jun 2009 16:09:08 +1200
Local: Sat, Jun 20 2009 12:09 am
Subject: Re: KeyboardInterrupt eats my error and then won't be caught

Philip Semanchuk wrote:
> try:
>    sem.acquire()   # User hits Ctrl + C while this is waiting
> except:
>    print "********* I caught it!"
> Instead a KeyboardInterrupt error is propagated up to the interpreter  
> and the process is killed as if the try/except wasn't there at all.

Not sure exactly what's happening, but I think I can guess.
Python installs a signal handler for Ctrl-C that sets a
flag in the interpreter. Every so many bytecodes executed,
the flag is checked and KeyboardInterrupt raised if it's
set.

So there can be a short delay between the Ctrl-C signal
being received and KeyboardInterrupt being raised, and it
seems that this delay results in it happening after the
try-except has exited.

You could try using signal.signal() to install a handler
for Ctrl-C that does nothing in a section around the
sem.acquire call(). That should prevent the KeyboardInterrupt
flag from being set, but the signal will still be occurring
at the Unix level, so the system call will get interrupted.

--
Greg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.