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

Method run_threads

Lib/test/test_queue.py:884–914  ·  view source on GitHub ↗
(self, n_threads, q, inputs, feed_func, consume_func)

Source from the content-addressed store, hash-verified

882 results.append(val)
883
884 def run_threads(self, n_threads, q, inputs, feed_func, consume_func):
885 results = []
886 sentinel = None
887 seq = inputs.copy()
888 seq.reverse()
889 rnd = random.Random(42)
890
891 exceptions = []
892 def log_exceptions(f):
893 def wrapper(*args, **kwargs):
894 try:
895 f(*args, **kwargs)
896 except BaseException as e:
897 exceptions.append(e)
898 return wrapper
899
900 feeders = [threading.Thread(target=log_exceptions(feed_func),
901 args=(q, seq, rnd, sentinel))
902 for i in range(n_threads)]
903 consumers = [threading.Thread(target=log_exceptions(consume_func),
904 args=(q, results, sentinel))
905 for i in range(n_threads)]
906
907 with threading_helper.start_threads(feeders + consumers):
908 pass
909
910 self.assertFalse(exceptions)
911 self.assertTrue(q.empty())
912 self.assertEqual(q.qsize(), 0)
913
914 return results
915
916 def test_basic(self):
917 # Basic tests for get(), put() etc.

Callers 4

test_orderMethod · 0.95
test_many_threadsMethod · 0.95

Calls 7

assertFalseMethod · 0.80
assertTrueMethod · 0.80
copyMethod · 0.45
reverseMethod · 0.45
emptyMethod · 0.45
assertEqualMethod · 0.45
qsizeMethod · 0.45

Tested by

no test coverage detected