9

I am new to multiprocessing. The following code properly illustrates what I am trying to do:

import pandas as pd
import multiprocessing
from joblib import Parallel, delayed

one = [True, False]
one_bla = pd.Series(one)
one_names = pd.Series(['Mr. Pea', 'Mrs. Pea'])

one_names = list(zip(one_names, one_names.index))

two = {}

def q():
    for k, m in one_bla.items():
        if one_bla.iloc[i] == True:
            two[i] = v

num_cores = multiprocessing.cpu_count()
results = Parallel(n_jobs=num_cores)(delayed(q) for i, v in one_names)

It's throwing me a TypeError: cannot unpack non-iterable function object. Could someone please see where I am making the mistake?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
user106742
  • 150
  • 1
  • 8

1 Answers1

16

the problem is the missing paranthesis after delayed(q) command. Try this;

results = Parallel(n_jobs=num_cores)(delayed(q)() for i, v in one_names)
Alper Aydın
  • 380
  • 1
  • 11
  • Yes, the correct way should pass the function to the first couple of parenthesis and the arguments that will be passed to that function inside the second couple of parenthesis – EuberDeveloper Apr 05 '21 at 16:49