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.