apex1
Regular Member
- May 29, 2015
- 217
- 182
I'm trying to have a basic counter in the 'test' function that increments for each iteration (list1 item).
I can't get it to work, been trying for hours. Any ideas what I'm doing wrong?
I can't get it to work, been trying for hours. Any ideas what I'm doing wrong?
Code:
from multiprocessing import Pool, Manager
def test(current_item, counter):
counter = counter + 1
print(counter)
print(current_item)
if __name__ == '__main__':
list1 = ["item1",
"item2",
"item3",
"item4",
"item5",
"item6",
"item7",
"item8",
"item9",
"item10",
"item11",
"item12"]
counter = Manager().Value(0)
p = Pool(4) # worker count
p.map(test, list1) # (function, iterable)
p.terminate()
p.join()