#!/usr/bin/env python
#-*-Coding:utf-8-*-
# Author:changhua Gong
Import random, time, queue
From multiprocessing.managers import Basemanager
From queue import queue
‘‘‘
Worker processes: Performing tasks, feedback results
This part of the content and the official website tutorial, some discrepancy
‘‘‘
# Inherit from Basemanager QueueManager
Class QueueManager (Basemanager):
Pass
# get the corresponding queue from the network
Queuemanager.register ("get_queue_t")
Queuemanager.register ("Get_queue_rs")
# Connect to the server, which is the machine running task_master.py:
SERVER_IP = "127.0.0.1"
Print ("Connect to server...%s"% server_ip)
Manager = QueueManager (server_ip, address=, authkey=b "love8013") # Ensure that the port and key are consistent
# from the network connection
Manager.connect ()
# Get a Queue object accessed over the network
t = manager.get_queue_t ()
rs = Manager.get_queue_rs ()
Print ("1")
# read a task from the task queue and write results to the result queue
For I in range (10):
Try
n = t.get (timeout=1)
Print (' Run task%d *%d ... '% (n, N))
R = '%d *%d =%d '% (n, N, n*n)
Time.sleep (1)
Rs.put (R)
Except Queue.empty:
Print (' Task queue is empty. ')
Print (' Worker exit. ')
Python Distributed Process Worker