MCPcopy Index your code
hub / github.com/python/cpython / test_notify_n

Method test_notify_n

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

Source from the content-addressed store, hash-verified

1924
1925 @warnings_helper.ignore_fork_in_thread_deprecation_warnings()
1926 def test_notify_n(self):
1927 cond = self.Condition()
1928 sleeping = self.Semaphore(0)
1929 woken = self.Semaphore(0)
1930
1931 # start some threads/processes
1932 workers = []
1933 for i in range(3):
1934 p = self.Process(target=self.f, args=(cond, sleeping, woken))
1935 p.daemon = True
1936 p.start()
1937 workers.append(p)
1938
1939 t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
1940 t.daemon = True
1941 t.start()
1942 workers.append(t)
1943
1944 # wait for them to all sleep
1945 for i in range(6):
1946 sleeping.acquire()
1947
1948 # check no process/thread has woken up
1949 time.sleep(DELTA)
1950 self.assertReturnsIfImplemented(0, get_value, woken)
1951
1952 # wake some of them up
1953 cond.acquire()
1954 cond.notify(n=2)
1955 cond.release()
1956
1957 # check 2 have woken
1958 self.assertReachesEventually(lambda: get_value(woken), 2)
1959
1960 # wake the rest of them
1961 cond.acquire()
1962 cond.notify(n=4)
1963 cond.release()
1964
1965 self.assertReachesEventually(lambda: get_value(woken), 6)
1966
1967 # doesn't do anything more
1968 cond.acquire()
1969 cond.notify(n=3)
1970 cond.release()
1971
1972 self.assertReturnsIfImplemented(6, get_value, woken)
1973
1974 # check state is not mucked up
1975 self.check_invariant(cond)
1976
1977 for w in workers:
1978 # NOTE: join_process and join_thread are the same
1979 threading_helper.join_thread(w)
1980
1981 def test_timeout(self):
1982 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