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

Method test_various_ops

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

Source from the content-addressed store, hash-verified

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

Calls 15

getMethod · 0.95
reprFunction · 0.85
hasattrFunction · 0.85
setFunction · 0.85
lenFunction · 0.85
BoundedSemaphoreMethod · 0.80
RLockMethod · 0.80
assertIsNoneMethod · 0.80
assertRegexMethod · 0.80
assertNotInMethod · 0.80
assertFalseMethod · 0.80
assertNotEqualMethod · 0.80

Tested by

no test coverage detected