0

I want to append list Python parallel processing. I write code as follow:

from joblib import Parallel
from multiprocessing.managers import BaseManager

manager = multiprocessing.Manager()
inputs = enumerate(my_list)
lproxy = manager.list()
d = lproxy
d.append([]) #init empty list

num_cores = multiprocessing.cpu_count()
_ = Parallel(n_jobs=num_cores)(d[0].append(word) for idx, word in inputs)

Then my parallel job return 'NoneType' object is not iterable. How to append to list in above case? In second example I test Parallel as follow:

from joblib import Parallel, delayed
def process(word) :
    print(word)
results = Parallel(n_jobs=num_cores)(delayed(process(word)) for idx, word in inputs)

and this return 'function' object is not iterable. Is this function have to be written somehow specially?

What's a god practice of parallel appending to the list?

1 Answer 1

0

It seems to be a solution:

import multiprocessing
inputs = enumerate(my_list)
manager = multiprocessing.Manager()
lproxy = manager.list()
from joblib import Parallel, delayed
def process(word) :
    lproxy.append(word)
results = Parallel(n_jobs=num_cores)(delayed(process)(word) for idx, word in inputs)

than to extract proxy list I use:

l = lproxy[:]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.