[Python-ideas] Protecting finally clauses of interruptions

Gregory P. Smith greg at krypto.org
Tue Apr 3 01:10:22 CEST 2012


On Mon, Apr 2, 2012 at 3:28 PM, Yury Selivanov <yselivanov.ml at gmail.com>wrote:

> On 2012-04-02, at 6:24 PM, Paul Colomiets wrote:
> >> I still don't get how exactly do you propose to handle sudden thread
> >> interruption in your own example:
> >>
> >> l.lock()
> >> # (!) the thread may be interrupted at this point
> >> try:
> >>   ...
> >> finally:
> >>   l.unlock()
> >>
> >> You don't have a 'with' statement here.
> >>
> >
> > By wrapping lock into a context manager.
>
> How's that going to work for tons of existing code?
>

A context manager doesn't solve this interruption "race condition" issue
anyways.

If the __enter__ method is interrupted it won't have returned a context and
thus __exit__ will never be called.

-gps


> -
> Yury
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120402/a40c5e99/attachment.html>


More information about the Python-ideas mailing list