On 28 June 2017 at 21:40, Erik Bray <[email protected]> wrote:
> My colleague's contention is that given
>
> lock = threading.Lock()
>
> this is simply *wrong*:
>
> lock.acquire()
> try:
>     do_something()
> finally:
>     lock.release()
>
> whereas this is okay:
>
> with lock:
>     do_something()

Technically both are slightly racy with respect to async signals (e.g.
KeyboardInterrupt), but the with statement form is less exposed to the
problem (since it does more of its work in single opcodes).

Nathaniel Smith posted a good write-up of the technical details to the
issue tracker based on his work with trio:
https://bugs.python.org/issue29988

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to