Why is SETUP_FINALLY uninterruptable[sic]?

David Pokorny davebrok at soda.csua.berkeley.edu
Wed Aug 18 00:24:15 CEST 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;
...     <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

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?


More information about the Python-list mailing list