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

Method run_threads

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

Source from the content-addressed store, hash-verified

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