I'm trying to use multiprocessing.pool to speed up some parsing of a file parsed using pyparsing, however I get a multiprocessing.pool.MaybeEncodingError exception whenever I try this.
I've narrowed it down to something to do with returning a dictionary (ParseResults.asDict()), using asList() the error doesn't occur; but the input I'm actually parsing is pretty complex so ideally I'd like to use asDict.
#!/usr/bin/env python2.7frompyparsingimport*importmultiprocessingvalue=(Word(alphas))key_val=Group(value+":"+value)lang=Dict(Suppress('[')+delimitedList(key_val)+Suppress(']'))defparse_dict(s):returnlang.parseString(s).asDict()defparse_list(s):returnlang.parseString(s).asList()data=['[ foo : bar ]']pool=multiprocessing.Pool()# This works (list)pool.map(parse_list,data)# This fails (dict)pool.map(parse_dict,data)
Fails with:
Traceback (most recent call last):
File "lib/python/nutshell/multi_parse.py", line 19, in <module>
pool.map(parse, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 250, in map
return self.map_async(func, iterable, chunksize).get()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 554, in get
raise self._value
multiprocessing.pool.MaybeEncodingError: Error sending result: '[{'foo': ([':', 'bar'], {})}]'. Reason: 'TypeError("'str' object is not callable",)'
Anyone got any suggestions?
Thanks,
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to use multiprocessing.pool to speed up some parsing of a file parsed using pyparsing, however I get a
multiprocessing.pool.MaybeEncodingError
exception whenever I try this.I've narrowed it down to something to do with returning a dictionary (
ParseResults.asDict()
), usingasList()
the error doesn't occur; but the input I'm actually parsing is pretty complex so ideally I'd like to useasDict
.Simplified testcase:
Fails with:
Anyone got any suggestions?
Thanks,
Dave