MCPcopy Create free account
hub / github.com/PyTables/PyTables / main

Function main

examples/simple_threading.py:59–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57
58
59def 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
101if __name__ == "__main__":

Callers 1

Calls 4

create_test_fileFunction · 0.70
chunk_generatorFunction · 0.70
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected