我正在使用Python处理Data Wrangling问题, 它将脏Excel文件处理成干净的Excel文件
我想通过引入并发/并行来处理多个输入文件。
我有以下选项1)使用multiThreading 2)使用multiProceesing模块3)ParallelPython模块,
我对这三种方法有基本的了解,我想知道哪种方法最好,为什么?
在Bref中,今天处理一个单个脏Excel文件需要3分钟,
目标:引入并行/并发来一次处理多个文件。 寻找,最好的并行方法来实现目标
答案 0 :(得分:0)
由于你的进程主要是CPU绑定的,因为GIL ...多线程不会很快...
我建议多处理或 concurrent.futures ,因为它们比ParallelPython稍微简单一些(只有一点点:))
示例:
with concurrent.futures.ProcessPoolExecutor() as executor:
for file_path, clean_file in zip(files, executor.map(data_wrangler, files)):
print('%s is now clean!' % (file_path))
#do something with clean_file if you want
只有当你需要在服务器之间分配负载时,我才会推荐ParallelPython。