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

Method test__count

Lib/test/test_thread.py:118–151  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

116 thread.stack_size(0)
117
118 def test__count(self):
119 # Test the _count() function.
120 orig = thread._count()
121 mut = thread.allocate_lock()
122 mut.acquire()
123 started = []
124
125 def task():
126 started.append(None)
127 mut.acquire()
128 mut.release()
129
130 with threading_helper.wait_threads_exit():
131 thread.start_new_thread(task, ())
132 for _ in support.sleeping_retry(support.LONG_TIMEOUT):
133 if started:
134 break
135 self.assertEqual(thread._count(), orig + 1)
136
137 # Allow the task to finish.
138 mut.release()
139
140 # The only reliable way to be sure that the thread ended from the
141 # interpreter's point of view is to wait for the function object to
142 # be destroyed.
143 done = []
144 wr = weakref.ref(task, lambda _: done.append(None))
145 del task
146
147 for _ in support.sleeping_retry(support.LONG_TIMEOUT):
148 if done:
149 break
150 support.gc_collect() # For PyPy or other GCs.
151 self.assertEqual(thread._count(), orig)
152
153 def test_unraisable_exception(self):
154 def task():

Callers

nothing calls this directly

Calls 5

_countMethod · 0.80
acquireMethod · 0.45
assertEqualMethod · 0.45
releaseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected