Skip to content

Commit 082892b

Browse files
committed
wip
1 parent 6a6aeaf commit 082892b

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Lib/multiprocessing/synchronize.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ def wait(self, timeout=None):
280280
self._woken_count.release()
281281
else:
282282
# we timed out, so remove ourselves from the sleeping count
283-
self._sleeping_count.acquire()
283+
# if possible.
284+
if not self._sleeping_count.acquire(False):
285+
print('+')
286+
self._woken_count.release()
284287

285288
# reacquire lock
286289
for i in range(count):
@@ -294,10 +297,13 @@ def notify(self, n=1):
294297

295298
# to take account of timeouts since last notify*() we subtract
296299
# woken_count from sleeping_count and rezero woken_count
297-
#while self._woken_count.acquire(False):
298-
# res = self._sleeping_count.acquire(False)
299-
# assert res, ('notify: Bug in sleeping_count.acquire'
300-
# + '- res should not be False')
300+
i = 0
301+
while self._woken_count.acquire(False):
302+
res = self._sleeping_count.acquire(False)
303+
assert res, ('notify: Bug in sleeping_count.acquire'
304+
+ '- res should not be False')
305+
i += 1
306+
print('.'*i, end='')
301307

302308
sleepers = 0
303309
while sleepers < n and self._sleeping_count.acquire(False):
@@ -310,6 +316,7 @@ def notify(self, n=1):
310316

311317
# rezero wait_semaphore in case some timeouts just happened
312318
while self._wait_semaphore.acquire(False):
319+
print(':', end='')
313320
pass
314321

315322
def notify_all(self):

Lib/test/_test_multiprocessing.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,9 @@ def _just_wait(cls, cond, sleeping, delay=None):
20422042

20432043
@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
20442044
def test_sleeping_count_invariant_when_elapsed_timeouts(self):
2045-
# See gh-69655.
2045+
# See gh-69655: In the `wait` method, exclude processes/threads
2046+
# that have exceeded the timeout from the list of pendings.
2047+
20462048
if self.TYPE != 'processes':
20472049
self.skipTest('test not appropriate for {}'.format(self.TYPE))
20482050

@@ -2052,8 +2054,8 @@ def test_sleeping_count_invariant_when_elapsed_timeouts(self):
20522054
for _ in range(n):
20532055
with cond:
20542056
cond.wait(0.0)
2055-
# Sempahore.locked() is equivalent to
2056-
# Semaphore._semlock._is_zero()
2057+
2058+
# Check there is no sleeper.
20572059
self.assertTrue(cond._sleeping_count.locked())
20582060
self.assertTrue(cond._woken_count.locked())
20592061

0 commit comments

Comments
 (0)