[ python-Bugs-771429 ] Signals discard one level of exception handling

SourceForge.net noreply at sourceforge.net
Tue Nov 9 12:16:36 CET 2004


Bugs item #771429, was opened at 2003-07-15 07:57
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=771429&group_id=5470

Category: Python Interpreter Core
Group: Python 2.1.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Dieter Maurer (dmaurer)
Assigned to: Nobody/Anonymous (nobody)
Summary: Signals discard one level of exception handling

Initial Comment:
Signals handled by Python (especially KeyboardInterrupt) 
may discard one level of exception handling.

Consider the following code fragment:

try: # outer exception handling level
  try: # inner exception handling level
    blocking_external_extension_function()
  except:
    print "inner exception handling"
except:
  print "outer exception handling"

Assume that "blocking_external_extension_function"
is an external function (implemented in "C") that
blocks until interrupted by a signal (EINTR) and
then returns with an exception but without handling
the signal. In our concrete case, 
"blocking_external_extension_function" has been
"psycopg.connect" (the database "connect" from the
Python-PostgreSQL bridge "psycopg").

In this case, when you interrupt the execution,
while "blocking_external_extension_function"
waits, the "KeyboardInterrupt" is not caught in
the inner "try: ...except: ..." but only in the outer
"try: ... except: ..."

The following happens in detail in Python's main 
interpreter loop:

  *  "blocking_external_extension_function" returns with
     an exception.

  *  Python sets the next instruction to the exception
     handler of the inner exception handling

  *  Python begins a new run through its main loop.
     At the start, it detects the "KeyboardInterrupt"
     signal. It now thinks, the "KeyboardInterrupt" were
     caused inside the inner exception handler
     and pops this exception handling level without
     executing it.

     The interpreter has lost one level of exception 
handling.

The behaviour would probably better fit with expectations, 
when the interpreter would check for signals at the end of 
its main loop and before it sets its instruction pointer to the 
exception handler. 


----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2004-11-09 11:16

Message:
Logged In: YES 
user_id=6656

In addition, attaching any code samples rather than including them 
would seem a good idea.  I can't make head or tail of the code in 
the summary.

----------------------------------------------------------------------

Comment By: Facundo Batista (facundobatista)
Date: 2004-11-08 23:45

Message:
Logged In: YES 
user_id=752496

Please, could you verify if this problem persists in Python 2.3.4
or 2.4?

If yes, in which version? Can you provide a test case?

If the problem is solved, from which version?

Note that if you fail to answer in one month, I'll close this bug
as "Won't fix".

Thank you! 

.    Facundo

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=771429&group_id=5470


More information about the Python-bugs-list mailing list