我该如何写入父级字典?我给一些子级一个url列表来获取数据,然后需要将这些数据写入到父级字典中:
from multiprocessing import Pool
import random
parent_dict={}
urls = ['www.yahoo.com','www.google.com','www.microsoft.com','www.apple.com','www.cisco.com']
def workit(url):
# retrieve the urls, process some stuff and then add that info to parent_dict
key = random.randrange(1,10) # pretend that this is the variable that we want in parent_dict
value = random.randrange(11,20)
parent_dict[key] = value
pool = Pool(processes = 5)
pool.map(workit,urls)
print parent_dict # returns {}}