From a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd Mon Sep 17 00:00:00 2001 From: Charles-François Natali Date: Sun, 25 May 2014 14:12:12 +0100 Subject: Issue #21565: multiprocessing: use contex-manager protocol for synchronization primitives. --- Lib/multiprocessing/synchronize.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'Lib/multiprocessing/synchronize.py') diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py index dea1cbd7f0b..7d443307313 100644 --- a/Lib/multiprocessing/synchronize.py +++ b/Lib/multiprocessing/synchronize.py @@ -337,34 +337,24 @@ class Event(object): self._flag = ctx.Semaphore(0) def is_set(self): - self._cond.acquire() - try: + with self._cond: if self._flag.acquire(False): self._flag.release() return True return False - finally: - self._cond.release() def set(self): - self._cond.acquire() - try: + with self._cond: self._flag.acquire(False) self._flag.release() self._cond.notify_all() - finally: - self._cond.release() def clear(self): - self._cond.acquire() - try: + with self._cond: self._flag.acquire(False) - finally: - self._cond.release() def wait(self, timeout=None): - self._cond.acquire() - try: + with self._cond: if self._flag.acquire(False): self._flag.release() else: @@ -374,8 +364,6 @@ class Event(object): self._flag.release() return True return False - finally: - self._cond.release() # # Barrier -- cgit v1.2.3