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