我如何写给父母的字典?我已经为一些孩子提供了一个要检索的 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 {}}