Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from multiprocessing import Manager,Pool
- def modify_dictionary(dictionary):
- if((3,3) not in dictionary):
- dictionary[(3,3)]=0.
- for i in range(100):
- dictionary[(3,3)] = dictionary[(3,3)]+1
- return 0
- if __name__ == "__main__":
- manager = Manager()
- dictionary = manager.dict(lock=True)
- jobargs = [(dictionary) for i in range(5)]
- p = Pool(5)
- t = p.map(modify_dictionary,jobargs)
- p.close()
- p.join()
- print dictionary[(3,3)]
- dictionary[(3,3)] = dictionary[(3,3)]+1
- from multiprocessing import Manager,Pool,Lock
- lock = Lock()
- def modify_array(dictionary):
- if((3,3) not in dictionary):
- dictionary[(3,3)]=0.
- for i in range(100):
- with lock:
- dictionary[(3,3)] = dictionary[(3,3)]+1
- return 0
- if __name__ == "__main__":
- manager = Manager()
- dictionary = manager.dict(lock=True)
- jobargs = [(dictionary) for i in range(5)]
- p = Pool(5)
- t = p.map(modify_array,jobargs)
- p.close()
- p.join()
- print dictionary[(3,3)]
- from multiprocessing import Process, Manager, Pool, Lock
- from functools import partial
- def f(dictionary, l, k):
- with l:
- for i in range(100):
- dictionary[3] += 1
- if __name__ == "__main__":
- manager = Manager()
- dictionary = manager.dict()
- lock = manager.Lock()
- dictionary[3] = 0
- jobargs = list(range(5))
- pool = Pool()
- func = partial(f, dictionary, lock)
- t = pool.map(func, jobargs)
- pool.close()
- pool.join()
- print(dictionary)
Add Comment
Please, Sign In to add comment