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

Function read_and_send_socket

examples/multiprocess_access_benchmarks.py:182–208  ·  view source on GitHub ↗
(
    send_type, array_size, array_bytes, address_func, socket_family
)

Source from the content-addressed store, hash-verified

180
181
182def read_and_send_socket(
183 send_type, array_size, array_bytes, address_func, socket_family
184):
185 address = address_func()
186 # start the receiving process and pause to allow it to start up
187 result_recv, result_send = multiprocessing.Pipe(False)
188 recv_process = SocketReceive(
189 socket_family, address, result_send, array_bytes
190 )
191 recv_process.start()
192 time.sleep(0.15)
193 with tb.open_file("test.h5", "r") as fobj:
194 array = fobj.get_node("/", "test")
195 start_timestamp = clock()
196 # connect to the receiving process' socket
197 sock = socket.socket(socket_family, socket.SOCK_STREAM)
198 sock.connect(address)
199 # read the array from the PyTables file and send its
200 # data buffer to the receiving process
201 output = array.read(0, array_size, 1)
202 sock.send(output.data)
203 assert np.all(output + 1 == 2)
204 # receive the timestamps from the other process
205 recv_timestamp, finish_timestamp = result_recv.recv()
206 sock.close()
207 print_results(send_type, start_timestamp, recv_timestamp, finish_timestamp)
208 recv_process.join()
209
210
211def print_results(

Calls 5

SocketReceiveClass · 0.85
print_resultsFunction · 0.85
get_nodeMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected