(self, n_threads, q, inputs, feed_func, consume_func)
| 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. |
no test coverage detected