首页 > 解决方案 > 如何通过串行将此索引文件更改为并行文件?

问题描述

我有这段代码来索引我的所有文件。它工作得非常好,我使用 python 对其进行编码,但如您所见,它是串行的。基本上它需要太多时间才能完成。大约。60 秒。据说,它应该能够并行运行得更快,但我真的不知道从现在开始该怎么做。感谢您提供任何帮助或提示,谢谢。

import os
import time

start = time.time()
handle = open("test.txt", "w")

rootDir = '/'
for dirName, subdirList, fileList in os.walk(rootDir):
    for fname in fileList:
        handle.write("%s\n" % os.path.abspath(os.path.join(dirName, fname)).encode('utf-8'))

handle.close()
end = time.time()
print(end-start)

标签: pythondistributed-system

解决方案


推荐阅读