1

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)
MahdiY
1,30222 silver badges32 bronze badges
asked Jun 22, 2017 at 12:39
2
  • what are the contents of buckList? Commented Jun 22, 2017 at 12:46
  • sorry my bad i mentioned as list of integers, it is actually list of strings buckList = ['Adasdas', 'Asdsd', 'Xsadsad', 'Ssdsd', 'Bdasdsds'] Commented Jun 22, 2017 at 12:54

1 Answer 1

1

You have 3 Options:

  • Queue()
  • Manager.Value()
  • Manager.list()

Python » Documentation: multiprocessing.html#managers

answered Jun 22, 2017 at 19:30
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.