[Python-ideas] Protecting finally clauses of interruptions

Paul Colomiets paul at colomiets.name
Mon Apr 2 22:49:21 CEST 2012

Hi Yury,

On Mon, Apr 2, 2012 at 11:37 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
> 1. Implement a mechanism to throw exceptions in running threads.  It should
> be possible to wake up thread if it waits on a lock, or any other syscall.

It's complex, because if thread waits on a lock you can't determine if it's
interrupted after lock or before. E.g. it's common to write:


Which will break if you interrupted just after lock is acquired.

> 2. Add 'f_in_finally' counter, as you proposed.


> 3. Either add a special base exception, that can be thrown in a currently
> executing frame to interrupt it, or add a special method to frame object
> 'f_interrupt()'. Once a frame is attempted to be interrupted, it checks
> its 'f_in_finally' counter.  If it is 0, then throw exception, if not -
> wait till it sets back to 0 and throw exception immediately.

Not sure how it supposed to work. If it's coroutine it may yield
while in finally, and you want it be interrupted only when it exits from


More information about the Python-ideas mailing list