[Python-ideas] Protecting finally clauses of interruptions

Paul Colomiets paul at colomiets.name
Sat Apr 7 13:11:00 CEST 2012


Hi Victor,

On Sat, Apr 7, 2012 at 1:04 PM, Victor Stinner <victor.stinner at gmail.com> wrote:
>> I'd like to propose a way to protect `finally` clauses from
>> interruptions (either by KeyboardInterrupt or by timeout, or any other
>> way).
>
> With Python 3.3, you can easily write a context manager disabling
> interruptions using signal.pthread_sigmask(). If a signal is send, the
> signal will be waiting in a queue, and the signal handler will be
> called when the signals are unblocked. (On some OSes, the signal
> handler is not called immediatly.)
>

And now you need to patch every library which happens to use `finally`
statement, to make it work. Doesn't seem to be realistic.

>
> You may hack ceval.c to not call the Python signal handler in a final
> block, but system calls will still be interrupted (EINTR).
>

This is not a problem for networking IO as it is always prepared for
EINTR, and posix mutexes never return EINTR. So for the primary
use-cases it's ok. But at least I'll add this consideration to the
PEP.

-- 
Paul



More information about the Python-ideas mailing list