[Python-ideas] Interrupting threads

MRAB python at mrabarnett.plus.com
Tue Jan 29 19:14:25 CET 2013


On 2013-01-29 08:52, Amaury Forgeot d'Arc wrote:
> 2013/1/29 Charles-François Natali <cf.natali at gmail.com
> <mailto:cf.natali at gmail.com>>
>
>      > The point has been made that you don't want an interruption in the
>      > middle of an exception handling routine. That's true. You also don't
>      > want an interruption in the middle of a 'finally' block.
>
>     That's a good start :-)
>
>
> But is it feasible?
> Is it possible to handle the case where a finally block calls another
> Python function?
>
On entry to a finally block, interruption/cancellation is
disabled/suppressed, and it remains disabled until the try statement is
exited normally, at which point the original state is restored.

However, the code in the finally block or in a function called from the
finally block could re-enable it for a section of code with the context
manager, but the context manager would save the current (disabled)
state on entry and restore it on exit.



More information about the Python-ideas mailing list