Example of pipeline usage in python
This example describes how to use pipelines in python. Share it with you for your reference. The details are as follows:
?
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 |
#! Coding = UTF-8 Import multiprocessing Def consumer (pipe ): Output_p, input_p = pipe Input_p.close () # Close the input of the Pipeline While True: Try: Item = output_p.recv () Failed t EOFError: Break Print item Print ("consumer done ") # Production project and put it on the queue Def producer (sequence, input_p ): For item in sequence: Input_p.send (item) If _ name _ = "_ main __": # Creating an MPS queue (Output_p, input_p) = multiprocessing. Pipe () # Start the user process Cons_p = multiprocessing. Process (target = consumer, args = (output_p, input_p ),)) Cons_p.start () # Close the output pipeline in the producer Output_p.close () # Production Project Sequence = [1, 2, 4] Producer (sequence, input_p) # Close the input media transcoding queue, indicating that the input media transcoding queue is complete. Input_p.close () # Waiting for the user to close Cons_p.join () |
I hope this article will help you with Python programming.