diff -r 2028aed246c0 Lib/multiprocessing/synchronize.py --- a/Lib/multiprocessing/synchronize.py Fri Oct 23 09:51:16 2015 -0700 +++ b/Lib/multiprocessing/synchronize.py Sat Oct 24 01:29:15 2015 +0100 @@ -259,7 +259,12 @@ try: # wait for notification or timeout - return self._wait_semaphore.acquire(True, timeout) + notified = self._wait_semaphore.acquire(True, timeout) + except: + notified = False + raise + else: + return notified finally: # indicate that this thread has woken self._woken_count.release() @@ -268,16 +273,15 @@ for i in range(count): self._lock.acquire() + # decrement counters since wasn't notified + if not notified: + self._woken_count.acquire(False) + self._sleeping_count.acquire(False) + def notify(self): assert self._lock._semlock._is_mine(), 'lock is not owned' assert not self._wait_semaphore.acquire(False) - # to take account of timeouts since last notify() we subtract - # woken_count from sleeping_count and rezero woken_count - while self._woken_count.acquire(False): - res = self._sleeping_count.acquire(False) - assert res - if self._sleeping_count.acquire(False): # try grabbing a sleeper self._wait_semaphore.release() # wake up one sleeper self._woken_count.acquire() # wait for the sleeper to wake @@ -289,12 +293,6 @@ assert self._lock._semlock._is_mine(), 'lock is not owned' assert not self._wait_semaphore.acquire(False) - # to take account of timeouts since last notify*() we subtract - # woken_count from sleeping_count and rezero woken_count - while self._woken_count.acquire(False): - res = self._sleeping_count.acquire(False) - assert res - sleepers = 0 while self._sleeping_count.acquire(False): self._wait_semaphore.release() # wake up one sleeper