
June 28, 2017
12:26 p.m.
On 28 June 2017 at 21:40, Erik Bray <erik.m.bray@gmail.com> 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 | ncoghlan@gmail.com | Brisbane, Australia