【发布时间】:2017-05-02 21:18:13
【问题描述】:
目前,这个嵌套的 for 循环需要将近一个小时才能运行完。我希望重写它并创建一些并行同步。我在任何地方都没有找到关于如何像下面这样嵌套的答案。任何指向正确方向的指针将不胜感激。
#used to update the Software Name's from softwareCollection using the regexCollection
startTime = time.time()
for x in softwareCollection.find({}, {"Software Name":-1,"Computer Name":-1,"Version":-1,"Publisher":-1,"reged": null }, no_cursor_timeout=True):
for y in regexCollection.find({}, {"regName": 1,"newName":1}, no_cursor_timeout=True):
try:
regExp = re.compile(y["regName"])
except:
print(y["regName"])
break
oldName = x["Software Name"]
newName = y["newName"]
if(regExp.search(oldName)):
x["Software Name"] = newName
x["reged"] = "true"
softwareCollection.save(x)
break
else:
continue
print(startTime - time.time() / 60)
cursor.close()
【问题讨论】:
-
你能进一步解释一下这是做什么的吗?
-
所以正在做的是从 mongoDB 列中获取软件名称,并将其与我保存在单独的 mongo 集合中的正则表达式查询列表进行比较。如果名称与正则表达式匹配,则将字段重命名为与该正则表达式关联的任何名称。
标签: python parallel-processing