Essentially, the two pipes, pipe_1 and pipe_2, are created by the multiprocessing.Pipe(True) statement:
pipe_1 = multiprocessing.Pipe(True)
pipe_2 = multiprocessing.Pipe(True)
The first pipe, pipe_1, simply created a list of integers from 0 to 9, while the second pipe, pipe_2, processed each element of the list created by pipe_1, calculating the squared value of each element:
process_pipe_2 =
multiprocessing.Process
(target=multiply_items, args=(pipe_1, pipe_2,))
Therefore, both processes are closed:
pipe_1[0].close()
pipe_2[0].close()
And the final result is printed:
print (pipe_2[1].recv())
Execute the code by typing the following command:
> python communicating_with_pipe.py
The following result shows the square of the first 9 digits:
0
1
4
9
16
25
36
49
64
81