def union_dict(objs): _keys = set(sum([obj.keys() for obj in objs], [])) _total = {} for _key in _keys: _total[_key] = sum([obj.get(_key, 0) for obj in objs]) return _total
def myprocess(data,i): labelnew=copy.deepcopy(labels) for afile in data[i*len(data)/num_of_process:(i+1)*len(data)/num_of_process]: statistics(afile, labelnew) return labelnew
if __name__=='__main__': e1 = time.time() pool = multiprocessing.Pool(processes = multiprocessing.cpu_count())#processes=4 in my mac result_list=[] data_train=open(train_set,'r').readlines() for i in xrange(num_of_process): #multiprocessing.Process(myprocess(target=myprocess,args=[data_train,i])) result=pool.apply_async(myprocess,(data_train,i)) result_list.append(result.get())