title: How do I avoid this pickling error, and what is the best way to parallelize this code in Python?
body: <p>I have the following code. </p>
  
  <pre><code>def main():
    (minI, maxI, iStep, minJ, maxJ, jStep, a, b, numProcessors) = sys.argv
    for i in range(minI, maxI, iStep):
      for j in range(minJ, maxJ, jStep): 
        p = multiprocessing.Process(target=functionA, args=(minI, minJ))
        p.start()
        def functionB((a, b)):
          subprocess.call('program1 %s %s %s %s %s %s' %(c, a, b, 'file1', 
            'file2', 'file3'), shell=True)
          for d in ['a', 'b', 'c']:
            subprocess.call('program2 %s %s %s %s %s' %(d, 'file4', 'file5', 
              'file6', 'file7'), shell=True)
        abProduct = list(itertools.product(range(0, 10), range(0, 10)))
        pool = multiprocessing.Pool(processes=numProcessors)
        pool.map(functionB, abProduct) 
  </code></pre>
  
  <p>It produces the following error. </p>
  
  <pre><code>Exception in thread Thread-1:
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
      self.run()
    File "/usr/lib64/python2.6/threading.py", line 484, in run 
      self.__target(*self.__args, **self.__kwargs)
    File "/usr/lib64/python2.6/multiprocessing/pool.py", line 255, in _handle_tasks
      put(task)
  PicklingError: Can't pickle &lt;type 'function'&gt;: attribute lookup __builtin__.function fa
  iled
  </code></pre>
  
  <p>The contents of functionA are unimportant, and do not produce an error. The error seems to occur when I try to map functionB. How do I remove this error, and what is the best way to parallelize this code in Python 2.6? </p>