diff options
author | Charles-François Natali <cf.natali@gmail.com> | 2014-05-25 13:12:12 (GMT) |
---|---|---|
committer | Charles-François Natali <cf.natali@gmail.com> | 2014-05-25 13:12:12 (GMT) |
commit | a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd (patch) | |
tree | cb29ab708c0a0c1f8ea51d20cdc7dbdd19a77046 /Lib/multiprocessing/synchronize.py | |
parent | 1691e35953858ae06b5198bf12c72a6cd0e0234b (diff) | |
download | cpython-a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd.zip cpython-a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd.tar.gz cpython-a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd.tar.bz2 |
Issue #21565: multiprocessing: use contex-manager protocol for synchronization
primitives.
Diffstat (limited to 'Lib/multiprocessing/synchronize.py')
-rw-r--r-- | Lib/multiprocessing/synchronize.py | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py index dea1cbd..7d44330 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 |