目前,此嵌套for循環需要將近一個小時才能完成。我希望重寫它並創建一些並行同步。我還沒有找到答案,如何做如下嵌套的東西。任何正確的方向指針將不勝感激。並行for循環,Python
#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()
你可以進一步解釋這是什麼嗎? – patrick
那麼現在要做的是從mongoDB列中取出軟件名稱,並將其與我保存在單獨的mongo集合中的正則表達式查詢列表進行比較。如果該名稱與正則表達式匹配,則將該字段重命名爲與該正則表達式關聯的任何名稱。 – Loglem