In-process Manager () for multi-process data sharing and delivery

Source: Internet
Author: User

__author__ = "Alex Li"

From multiprocessing import Process, Manager
Import OS
def f (D, L):
D[os.getpid ()] =os.getpid ()
L.append (Os.getpid ())
Print (L)

if __name__ = = ' __main__ ':
With manager () as manager:
D = manager.dict () #{} #生成一个字典 that can be shared and delivered across multiple processes

L = manager.list (range (5)) #生成一个列表 that can be shared and delivered across multiple processes
P_list = []
For I in range (10):
p = Process (Target=f, args= (d, L))
P.start ()
P_list.append (P)
For res in p_list: #等待结果
Res.join ()

Print (d)
Print (L)


‘‘‘
Manager () acts as a translator between processes, and if there are 10 processes, there will be 10 identical data for multiple inter-process sharing and delivery
‘‘‘

Manager in Process () for multi-process data sharing and delivery

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.