Python implements MPs queues and python implements MPs queues.
This article describes how to process pipelines in Python. Share it with you for your reference. The specific analysis is as follows:
What is the most amazing magic in Linux? I believe different people have different opinions, but if there is no pipeline, I am afraid that magic will be lost in the beautiful magic.
This section describes how to use Python to process these pipelines.
Pipeline call subroutine
We want to use a sub-program in the program, but we need to dynamically PASS Parameters (the dynamic here refers to deciding what to input based on the results of the previous subprogram input). What should we do, don't worry, there is subprocess!
Next I will first introduce an example code and its output results!
#! /Usr/bin/pythonfrom subprocess import * # Subprocess management, which can be used to create many sub-process files. We need to introduce this file p = Popen (["cat ", "-n"], bufsize = 1024, stdin = PIPE, stdout = PIPE, close_fds = True) # The first parameter to open a program is a list (program name, parameter) # The second parameter is the buffer size # stdin. stdout is used to set whether to open these pipelines, if its value is subprocess. PIPE, # Will open. Like stdin, stderr # close_fds is set to true (unix-only). All file descriptors except (0, 1, 2) close (fin, fout) = (p. stdin, p. stdout) for I in range (10): # mongo_^ fin. write ("line" + str (I) fin. write ('\ n') fin. flush () print fout. readline ()
The output result is:
Line0line1line2line3line4line5line6line7line8line9
I hope this article will help you with Python programming.