在Python中启动新流程,而不是重用以前的流程

在Python中启动新流程,而不是重用以前的流程,python,python-multiprocessing,Python,Python Multiprocessing,我在Python中使用多处理,包括: import multiprocessing as mp all_arguments = range(0,20) pool = mp.Pool(processes=7) all_items = [pool.apply_async(main_multiprocessing_function, args=(argument_value,)) for argument_value in all_arguments] for item in all_items:

我在Python中使用多处理,包括:

import multiprocessing as mp
all_arguments = range(0,20)

pool = mp.Pool(processes=7) 
all_items = [pool.apply_async(main_multiprocessing_function, args=(argument_value,)) for argument_value in all_arguments]
for item in all_items:
    item.get()
在上面的例子中,据我所知,在一个辅助处理器完成后,它将转到下一个值。有没有办法强迫“新”工作处理器每次都从头开始初始化,而不是重复使用旧的

[具体地说,
main\u multiprocessing\u function
调用多个其他函数,每个函数都使用缓存来加速每个任务中的处理。但是,对于下一个要处理的项目,所有这些缓存都是冗余的,因此我感兴趣的是如何将所有内容重置为新的]

来自:

maxtasksperchild是工作进程可以完成的任务数 在退出并替换为新员工流程之前 允许释放未使用的资源。默认的maxtasksperchild为 无,这意味着工作进程将与池一样长

只需将池创建为

pool = mp.Pool(processes=7, maxtasksperchild=1)
从:

maxtasksperchild是工作进程可以完成的任务数 在退出并替换为新员工流程之前 允许释放未使用的资源。默认的maxtasksperchild为 无,这意味着工作进程将与池一样长

只需将池创建为

pool = mp.Pool(processes=7, maxtasksperchild=1)
旁注:旁注: