Thursday, September 19, 2013

Python: Multiprocessing: xlrd workbook can't be passed as argument

import multiprocessing as mp, xlrd

def myfun(b):
  print b.sheet_names()

b=xlrd.open_workbook('../../Notes/sessions_and_neurons.xlsx')
p = mp.Pool(4)
p.map(myfun, [b,b,b,b])
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 319, in _handle_tasks
    put(task)
PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed

No comments:

Post a Comment