from multiprocessing import Pool
def init_pool(the_list):
global some_list
some_list = the_list
def access_some_list(index):
return some_list[index]
if __name__ == "__main__":
some_list = [24, 12, 6, 3]
indexes = [3, 2, 1, 0]
pool = Pool(initializer=init_pool, initargs=(some_list,))
result = pool.map(access_some_list, indexes)
print(result)
在创建进程池的时候只想初始化操作