()
| 57 | |
| 58 | |
| 59 | def main(): |
| 60 | # generate the test data |
| 61 | if not Path(FILENAME).exists(): |
| 62 | create_test_file(FILENAME) |
| 63 | |
| 64 | threads = [] |
| 65 | inqueue = queue.Queue() |
| 66 | outqueue = queue.Queue() |
| 67 | |
| 68 | # start all threads |
| 69 | for _ in range(NTHREADS): |
| 70 | thread = threading.Thread( |
| 71 | target=run, args=(FILENAME, H5PATH, inqueue, outqueue) |
| 72 | ) |
| 73 | thread.start() |
| 74 | threads.append(thread) |
| 75 | |
| 76 | # push requests in the input queue |
| 77 | for yslice in chunk_generator(SIZE, len(threads)): |
| 78 | inqueue.put(yslice) |
| 79 | |
| 80 | # collect results |
| 81 | try: |
| 82 | mean_ = 0 |
| 83 | |
| 84 | for _ in range(len(threads)): |
| 85 | out = outqueue.get() |
| 86 | if isinstance(out, Exception): |
| 87 | raise out |
| 88 | else: |
| 89 | mean_ += out |
| 90 | |
| 91 | mean_ /= SIZE * SIZE |
| 92 | |
| 93 | finally: |
| 94 | for thread in threads: |
| 95 | thread.join() |
| 96 | |
| 97 | # print results |
| 98 | print(f"Mean: {mean_}") |
| 99 | |
| 100 | |
| 101 | if __name__ == "__main__": |
no test coverage detected