Example of Python inter-process communication usage and python process usage

Source: Internet
Author: User

Example of Python inter-process communication usage and python process usage

This example describes the communication usage between Python processes. Share it with you for your reference. The details are as follows:

#! /Usr/bin/env python #-*-coding = UTF-8-*-import multiprocessingdef counsumer (input_q): while True: item = input_q.get () # processing project print item # replace this with useful work # sending a signal to notify the task to complete input_q.task_done () def producer (sequence, output_q): for item in sequence: # Put the project into the queue output_q.put (item) # create the process if _ name _ = '_ main _': q = multiprocessing. joinableQueue () # create a connectable shared process queue cons_q = multiprocessing. process (target = counsumer, args = (q,) cons_q.daemon = True cons_q.start () sequence = [1, 2, 4] producer (sequence, q) q. join () print 'success'

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.