Why is SETUP_FINALLY uninterruptable[sic]?

Jeff Epler jepler at unpythonic.net
Wed Aug 18 03:56:47 CEST 2004


Well, it's not an answer per se, but this block of code was added at the
same time as PyThreadState_SetAsyncExc, which is a C API to allow
raising an exception from an arbitrary thread.

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Python/ceval.c#rev2.366

I suspect that this has something to do with code like

    l = some_lock()
    l.acquire()
                    # MARK
    try:
        something with l held
    finally:
        l.release()
If an asynchronous exception happens betwen l.acquire() and the
SETUP_FINALLY opcode (at "MARK") , there's no guarantee that l.release()
is executed.

This state of affairs always existed with KeyboardInterrupt and/or
signals, and it's hard to see how this fixes the problem if l.acquire()
is Python code, but I think that's what's going on.

The special magic is only applied to SETUP_FINALLY because try: except:
isn't used for this kind of resource management.

This is all guesswork, though.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040817/ec540610/attachment.pgp>


More information about the Python-list mailing list