Python implements MPs queues and python implements MPs queues.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.