I tried to rewrite some csv code to be able to run it on multiple cores in Python 3.2.2. I tried to use the Multiprocessor Pool object, which I adapted from working examples (and already worked for me for another part of my project). I came across an error message that was difficult for me to decrypt and fix.
Mistake:
Traceback (most recent call last): File "parser5_nodots_parallel.py", line 256, in <module> MG,ppl = csv2graph(r) File "parser5_nodots_parallel.py", line 245, in csv2graph node_chunks) File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/multiprocessing/pool.py", line 552, in get raise self._value AttributeError: __exit__
Relevant Code:
import csv import time import datetime import re from operator import itemgetter from multiprocessing import Pool import itertools def chunks(l,n): """Divide a list of nodes 'l' in 'n' chunks""" l_c = iter(l) while 1: x = tuple(itertools.islice(l_c,n)) if not x: return yield x def csv2nodes(r): strptime = time.strptime mktime = time.mktime l = [] ppl = set() pattern = re.compile(r"""[A-Za-z0-9"/]+?(?=[,\n])""") for row in r: with pattern.findall(row) as f: cell = int(f[3]) id = int(f[2]) st = mktime(strptime(f[0],'%d/%m/%Y')) ed = mktime(strptime(f[1],'%d/%m/%Y'))
What a good way to fix this?
László Sep 16 '11 at 15:48 2011-09-16 15:48
source share