I have a list of strings and I want to bucket these list elements into appropriate buckets.
def bucketElements(i):
global buckA, buckB, buckC
if i.startswith('A'):
buckA.add(i)
elif i.startswith('B'):
buckB.add(i)
elif i.startswith('C'):
buckC.add(i)
Now I want to call this method in parallel for each element inside my List. Something like this,
buckA,buckB, buckC = set(), set(), set()
pool = multiprocessing.Pool(processes=10)
pool.map(bucketElements, buckList)
Since I'm updating global variables inside my function I cannot use multiprocessing. is there anyway I can improve my processing? currently I'm calling it like this,
buckA,buckB, buckC = set(), set(), set()
for i in buckList:
bucketElements(i)
asked Jun 22, 2017 at 12:39
MikA
5,6125 gold badges36 silver badges42 bronze badges
1 Answer 1
You have 3 Options:
Queue()Manager.Value()Manager.list()
Python » Documentation: multiprocessing.html#managers
answered Jun 22, 2017 at 19:30
stovfl
15.6k7 gold badges26 silver badges54 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-py
buckList?