shared list in multiprocessing python

Solutions on MaxInterview for shared list in multiprocessing python by the best coders in the world

showing results for - "shared list in multiprocessing python"
Monica
18 May 2018
1import multiprocessing
2manager = multiprocessing.Manager()
3shared_list = manager.list()
4
5def worker1(l):
6    l.append(1)
7
8def worker2(l):
9    l.append(2)
10
11process1 = multiprocessing.Process(
12    target=worker1, args=[shared_list])
13process2 = multiprocessing.Process(
14    target=worker2, args=[shared_list])
15
16process1.start()
17process2.start()
18process1.join()
19process2.join()
20
21print shared_listOutput[1, 2]
22