MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_notify_n

Method test_notify_n

Lib/test/_test_multiprocessing.py:1726–1779  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1724 threading_helper.join_thread(w)
1725
1726 def test_notify_n(self):
1727 cond = self.Condition()
1728 sleeping = self.Semaphore(0)
1729 woken = self.Semaphore(0)
1730
1731 # start some threads/processes
1732 workers = []
1733 for i in range(3):
1734 p = self.Process(target=self.f, args=(cond, sleeping, woken))
1735 p.daemon = True
1736 p.start()
1737 workers.append(p)
1738
1739 t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
1740 t.daemon = True
1741 t.start()
1742 workers.append(t)
1743
1744 # wait for them to all sleep
1745 for i in range(6):
1746 sleeping.acquire()
1747
1748 # check no process/thread has woken up
1749 time.sleep(DELTA)
1750 self.assertReturnsIfImplemented(0, get_value, woken)
1751
1752 # wake some of them up
1753 cond.acquire()
1754 cond.notify(n=2)
1755 cond.release()
1756
1757 # check 2 have woken
1758 self.assertReachesEventually(lambda: get_value(woken), 2)
1759
1760 # wake the rest of them
1761 cond.acquire()
1762 cond.notify(n=4)
1763 cond.release()
1764
1765 self.assertReachesEventually(lambda: get_value(woken), 6)
1766
1767 # doesn't do anything more
1768 cond.acquire()
1769 cond.notify(n=3)
1770 cond.release()
1771
1772 self.assertReturnsIfImplemented(6, get_value, woken)
1773
1774 # check state is not mucked up
1775 self.check_invariant(cond)
1776
1777 for w in workers:
1778 # NOTE: join_process and join_thread are the same
1779 threading_helper.join_thread(w)
1780
1781 def test_timeout(self):
1782 cond = self.Condition()

Callers

nothing calls this directly

Calls 15

startMethod · 0.95
acquireMethod · 0.95
notifyMethod · 0.95
check_invariantMethod · 0.95
SemaphoreMethod · 0.80
join_threadMethod · 0.80
get_valueFunction · 0.70
ConditionMethod · 0.45
ProcessMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected