Python Distributed Process

Source: Internet
Author: User

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

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.