I am trying to use multiprocessing.poolto speed up parsing a file using pyparsing, however, I get an exception multiprocessing.pool.MaybeEncodingErrorwhenever I try to do this.
I narrowed it down to something related to returning dictionary ( ParseResults.asDict()), using the asList()error does not occur; but the input that I actually parses is quite complicated, so I would like to use asDict.
The actual parsed data is a list of tagged Erlang tags that I want to map to a python list. The grammar for this is pretty complicated, so instead I got a simplified test case ( updated to include a nested dict ):
from pyparsing import *
import multiprocessing
dictionary = Forward()
key = Word(alphas)
sep = Suppress(":")
value = ( key | dictionary )
key_val = Group( key + sep + value )
dictionary <<= Dict( Suppress('[') + delimitedList( key_val ) + Suppress(']') )
def parse_dict(s):
p = dictionary.parseString(s).asDict()
return p
def parse_list(s):
return dictionary.parseString(s).asList()
data = ['[ foo : [ bar : baz ] ]']
pool = multiprocessing.Pool()
pool.map(parse_list, data)
pool.map(parse_dict, data)
Failure:
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', 'baz'], {})], {'bar': [('baz', 0)]})}]'. Reason: 'TypeError("'str' object is not callable",)'