aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/multiprocessing/synchronize.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/multiprocessing/synchronize.py')
-rw-r--r--Lib/multiprocessing/synchronize.py24
1 files changed, 5 insertions, 19 deletions
diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py
index d4bdf0e8b17..0590ed68f53 100644
--- a/Lib/multiprocessing/synchronize.py
+++ b/Lib/multiprocessing/synchronize.py
@@ -268,24 +268,7 @@ class Condition(object):
for i in range(count):
self._lock.acquire()
- 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
-
- # rezero _wait_semaphore in case a timeout just happened
- self._wait_semaphore.acquire(False)
-
- def notify_all(self):
+ def notify(self, n=1):
assert self._lock._semlock._is_mine(), 'lock is not owned'
assert not self._wait_semaphore.acquire(False)
@@ -296,7 +279,7 @@ class Condition(object):
assert res
sleepers = 0
- while self._sleeping_count.acquire(False):
+ while sleepers < n and self._sleeping_count.acquire(False):
self._wait_semaphore.release() # wake up one sleeper
sleepers += 1
@@ -308,6 +291,9 @@ class Condition(object):
while self._wait_semaphore.acquire(False):
pass
+ def notify_all(self):
+ self.notify(n=sys.maxsize)
+
def wait_for(self, predicate, timeout=None):
result = predicate()
if result: