import pathos.multiprocessing as mp
class Model_Output_File():
"""
Class to read Model Output files
"""
def __init__(self, ftype = ''):
"""
Constructor
"""
# Create a sqlite database in the analysis directory
self.db_name = 'sqlite:///' + constants.anly_dir + os.sep + ftype + '_' + '.db'
self.engine = create_engine(self.db_name)
self.ftype = ftype
def parse_DGN(self, fl):
df = pandas.read_csv(...)
df.to_sql(self.db_name, self.engine, if_exists='append')
def collect_epic_output(self, fls):
pool = mp.ProcessingPool(4)
if(self.ftype == 'DGN'):
pool.map(self.parse_DGN, fls)
else:
logging.info( 'Wrong file type')
if __name__ == '__main__':
list_fls = fnmatch.filter(...)
obj = Model_Output_File(ftype = 'DGN')
obj.collect_model_output(list_fls)
In the code above, I am using the pathos multiprocessing library to avoid python multiprocessing issues with classes. However I am getting a pickling error:
pool.map(self.parse_DGN, fls)
File "C:\Anaconda64\lib\site-packages\pathos-0.2a1.dev0-py2.7.egg\pathos\multiprocessing.py", line 131, in map
return _pool.map(star(f), zip(*args)) # chunksize
File "C:\Anaconda64\lib\multiprocessing\pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "C:\Anaconda64\lib\multiprocessing\pool.py", line 567, in get
raise self._value
cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
How do I fix this?
pathosauthor. You are getting acPickle.PicklingError… which you should not get withpathos. Do you havemultiprocessinstalled, and if you do, do you have a C compiler? You can check for pickling errors by importingdill, and doing adill.copyon the object. If that works, then you probably have some installation issue, wherepathosis finding the standard library version ofmultiprocessingand not the fork that provides better serialization. - Mike McKernsdill.copy(self.parse_DGN). So if you are finding the python standard librarymultiprocessing, then you probably need to install a compiler… like Microsoft Visual Studio Community. See: github.com/mmckerns/tuthpc - Mike McKernsmultiprocessafter the install of the MS compiler? - Mike McKernsmultiprocessshould justpip installwith no problems. Maybe you can post this as a ticket on themultiprocessgithub page? That way, I can better diagnose your traceback? The only other thing I can think of w/o seeing tracebacks / build output is that you have an unusual PYTHONPATH. - Mike McKerns