-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_pipes.py
More file actions
31 lines (24 loc) · 758 Bytes
/
multi_pipes.py
File metadata and controls
31 lines (24 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import time
from multiprocessing import Pipe, Process
def reader_proc(pipe):
p_output, p_input = pipe
p_input.close()
while True:
msg = p_output.recv()
if msg == "DONE":
break
def writer(count, p_input):
for i in range(count):
p_input.send(i)
p_input.send("DONE")
if __name__ == "__main__":
for count in [10**4, 10**5, 10**6]:
p_output, p_input = Pipe()
reader_p = Process(target=reader_proc, args=((p_output, p_input),))
reader_p.daemon = True
reader_p.start()
_start = time.time()
writer(count, p_input)
p_output.close()
reader_p.join()
print(f"Sending {count} numbers to Pipe() took {time.time() - _start} seconds")