Python inter-process communication usage example

Source: Internet
Author: User
This article mainly introduces the usage of Python inter-process communication, and involves the skills related to Python operating processes through the multiprocessing module. If you need it, refer to the following example to describe the usage of Python inter-process communication. 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.

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.