繁体   English   中英

Python dask程序即使看起来可以计算也无法产生输出

[英]Python dask program failing to produce output even though it seems to compute

我对为什么我的dask程序不产生任何输出感到困惑,它只是在提交后挂起。 我已指定使用进程而不是线程,并且可以看到所有内核在提交时启动(如此处建议: dask计算不并行执行 ),因此它似乎可以计算但从未完成。 我只是想在长文本文件列表上运行一个简单的正则表达式。 我是否缺少明显的东西?

import re
from os import listdir

import dask.bag as db
import dask.multiprocessing
dask.set_options(get=dask.multiprocessing.get)


loc = 'D:\\...\\text_files\\'
txts = [loc + i for i in listdir(loc)[:10]]

#  Load data in parallel
f = db.from_filenames(txts)
f = f.repartition(3)

# Define the regex
regex = re.compile(r'\b[A-Z][a-z]+\b')

# create function to parallelize
def reg(text):
    return regex.findall(text)

# distribute the function over cores
output = f.map(reg).compute().concat()

两个建议:

  1. 挂断电话以repartition 这将实例化数据,然后尝试在进程之间移动它,这通常很昂贵。 您应该信任系统提供的默认值。 它只会使用与内核一样多的进程。

  2. 仅在计算结束时才调用.compute() 您可能希望交换以下两行:

     output = f.map(reg).compute().concat() # before output = f.map(reg).concat().compute() # after 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM