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

Method test_various_ops

Lib/test/test_threading.py:199–233  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

197 # Create a bunch of threads, let each do some work, wait until all are
198 # done.
199 def test_various_ops(self):
200 # This takes about n/3 seconds to run (about n/3 clumps of tasks,
201 # times about 1 second per clump).
202 NUMTASKS = 10
203
204 # no more than 3 of the 10 can run at once
205 sema = threading.BoundedSemaphore(value=3)
206 mutex = threading.RLock()
207 numrunning = Counter()
208
209 threads = []
210
211 for i in range(NUMTASKS):
212 t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
213 threads.append(t)
214 self.assertIsNone(t.ident)
215 self.assertRegex(repr(t), r'^<TestThread\(.*, initial\)>$')
216 t.start()
217
218 if hasattr(threading, 'get_native_id'):
219 native_ids = set(t.native_id for t in threads) | {threading.get_native_id()}
220 self.assertNotIn(None, native_ids)
221 self.assertEqual(len(native_ids), NUMTASKS + 1)
222
223 if verbose:
224 print('waiting for all tasks to complete')
225 for t in threads:
226 t.join()
227 self.assertFalse(t.is_alive())
228 self.assertNotEqual(t.ident, 0)
229 self.assertIsNotNone(t.ident)
230 self.assertRegex(repr(t), r'^<TestThread\(.*, stopped -?\d+\)>$')
231 if verbose:
232 print('all tasks done')
233 self.assertEqual(numrunning.get(), 0)
234
235 def test_ident_of_no_threading_threads(self):
236 # The ident still must work for the main thread and dummy threads.

Calls 15

getMethod · 0.95
TestThreadClass · 0.85
setFunction · 0.85
BoundedSemaphoreMethod · 0.80
RLockMethod · 0.80
assertIsNoneMethod · 0.80
assertRegexMethod · 0.80
assertNotInMethod · 0.80
assertFalseMethod · 0.80
assertNotEqualMethod · 0.80
assertIsNotNoneMethod · 0.80
CounterClass · 0.70

Tested by

no test coverage detected