[ python-Bugs-771429 ] Signals discard one level of exception
handling
SourceForge.net
noreply at sourceforge.net
Sat Jan 15 22:27:22 CET 2005
Bugs item #771429, was opened at 2003-07-15 03:57
Message generated for change (Settings changed) made by facundobatista
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: Closed
>Resolution: Wont Fix
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: Facundo Batista (facundobatista)
Date: 2005-01-15 18:26
Message:
Logged In: YES
user_id=752496
Deprecated. Reopen only if still happens in 2.3 or newer.
. Facundo
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2004-11-09 08:33
Message:
Logged In: YES
user_id=6656
Oh, after some judicious view-sourcing and query-replacing, I get
the problem. However, I can't reproduce it (see attached script).
So we're back to needing a failing example and more platform
details.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2004-11-09 08: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 20: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