Distributed process can be arranged in the LAN, the scheduled tasks are registered in the LAN, the different hosts can transfer information, so as to assign tasks and feedback, but not suitable for returning large amounts of data;
First, you need a server to hold the data, other machines through the LAN IP access to:
#-*-coding:utf-8-*-#registration process, Manager/serverImportMultiprocessing fromMultiprocessing.managersImportBasemanager fromMultiprocessingImportFreeze_support#QueueManager inherited from Basemanager:classQueueManager (basemanager):Pass#queue for sending tasks:Task_queue =multiprocessing. Queue ()#queue to receive results:Result_queue =multiprocessing. Queue ()#to solve the problem of __main__.<lambda> not founddefget_task_queue ():returnTask_queue#to solve the problem of __main__.<lambda> not founddefget_result_queue ():returnResult_queue#register two queues on the network, the callable parameter is associated with the queue object:Queuemanager.register ('Get_task_queue', callable=get_task_queue) Queuemanager.register ('Get_result_queue', callable=get_result_queue)#bind Port 5000, set the Captcha ' abc ':Manager = QueueManager (address= ('192.168.10.138', authkey=),'ABC') Freeze_support ()#Manager.start () is not functioning properly, use the following method as a process communication serverServer =manager.get_server () server.serve_forever ( )
Using Server.serve_forever () to turn on a process communication server, the process itself is blocked, and is always stored as a process for communicating data.
Other processes can access and modify the communication data of the server process to achieve the purpose of transmitting information.
#_*_ coding:utf-8 _*_"""a work Manager sample"""ImportQueue fromMultiprocessing.managersImportBasemanagerImport TimeclassQueueManager (basemanager):Pass #get the queue from the networkQueuemanager.register ('Get_task_queue') Queuemanager.register ('Get_result_queue')#connecting to a serverSERVER_ADDR ='192.168.10.141'Print 'Connect to server%s ...'%Server_addrmanager= QueueManager (address= (SERVER_ADDR,), authkey='ABC') Manager.connect ()#get the Queue objectTask =manager.get_task_queue () result= Manager.get_result_queue ()
Note the IP and port registered to the server are consistent with the communication server side.
The processes in the LAN exchange information indirectly through the server.
Python Distributed Process