run
Pool.map_async を使用して並列に数回実行したいユーザー定義関数を含む単純なスクリプトがあります。試してみると、次のエラーが表示されます。
def getKey(where, key):
found = re.search('<td.*?>%s:</td>.*?<td>(.*?)</td>' % key, where, re.DOTALL).group(1)
return re.sub('<[^>]*?>', "", found).strip()
def extract(sitename):
text = urllib.urlopen(sitename).read()
return getKey(text, 'Name')
def run(start, span):
links = get(start, span)
if (len(links) == 0): return
pool = Pool(span)
pool.map_async(extract, links).get()
pool.close()
pool.join()
run(start + span, span)
run(0, 50)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
http://docs.python.org/library/multiprocessing.htmlに記載されていますが、それFunctionality within this package requires that the __main__ module be importable by the children
が実際に何を意味するのか、この問題を解決するにはどうすればよいのかわかりません。ご意見をお聞かせください。