Why is SETUP_FINALLY uninterruptable[sic]?

David Pokorny davebrok at soda.csua.berkeley.edu
Tue Aug 17 18:24:15 EDT 2004


Whilst swimming through Python/ceval.c, I came upon the following:

PyEval_EvalFrame(...) {
...
<main interpreter loop>
...
    if (--_Py_Ticker < 0) {
        if (*next_instr == SETUP_FINALLY) {
                                    /* Make the last opcode before
                                       a try: finally: block
uninterruptable. */
               goto fast_next_opcode;
        }
        _Py_Ticker = _Py_CheckInterval;
        tstate->tick_counter++;
...     <do "occasional" things like let other threads run, ... occurs every
sys.getcheckinterval() bytecodes>
}

I've been trying to find a good reason _why_ the main loop shouldn't perform
the check at the usual time in the (highly rare)
situation where SETUP_FINALLY occurs as the last instruction before a check.
So far, I've managed to confuse myself even further and
come up with another stumper: what makes SETUP_FINALLY more special than
SETUP_LOOP and SETUP_EXCEPT?

The best answer I can think of is this: if another thread ran in between the
SETUP_FINALLY and the next first instruction of the
try block, then this other thread might step on some globals that
SETUP_FINALLY uses to communicate to the try block. As far as I can tell, no
such communication takes place and this isn't the reason.

Could a Python guru please enlighten me?

David





More information about the Python-list mailing list