python - 如何通过串行将此索引文件更改为并行文件?
问题描述
我有这段代码来索引我的所有文件。它工作得非常好,我使用 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)
解决方案
推荐阅读
- git - 裸存储库的 git log 中缺少远程分支
- javascript - 如何在 Node.js 上使用 JS 库?
- typescript - 如果一种扩展另一种,有没有办法定义两种类型的联合类型?
- java - 如何从 byte[](字节码)创建 java.lang.Class 对象?
- css - 我无法定义侧边栏的背景
- prebid.js - 如何使用 github 更新自定义预投标版本?
- magento - 访问当前的可配置产品配置
- reactjs - REACT/REDUX:如何将 Store 连接到 App 组件?
- regex - 正则表达式(PCRE)向前/向后包含以匹配结果
- sql - 查询每个产品的总价值