Python - make_archive 多进程池中的 zip 无法正常工作

Python - make_archive zip in multiprocess pool not working properly

我想同时从多个进程创建一个 zip 存档。 当我从多处理中使用池时。 一些 zip 存档尚未创建。 似乎关闭方法不等待进程结束 在进程启动器下方:

import os
import sys
import json
from multiprocessing import Pool
from shutil import copyfile, make_archive
from xml.etree.ElementTree import ElementTree

def launch_traitment(path, path_upload):
    print(path)
    with Pool(processes=NB_PROCESS) as pool:
        for dir in os.listdir(path):
            pool.apply_async(compute_dir,(dir,path,path_upload,))
        pool.close()
        pool.join()
...
def compute_dir(dir, path, path_upload):

    working_path = path+'/'+dir
    deleteAck(working_path+'/'+dir+'.ack')
    execute(dir, path)
    generateZIP(dir, working_path, path_upload)
...
def generateZIP(dir, working_path, path_upload):
    lst_file_meta_data = dir.split('_')
    if len(lst_file_meta_data) < 3:
        print(f"File {dir} incorrect naming")
        return 1

    provider = lst_file_meta_data[0]
    registration = lst_file_meta_data[1]
    session_date = lst_file_meta_data[2]

    zip_file = path_upload+'/'+provider+'/'+registration

    if not os.path.exists(zip_file+'/'+ dir +'.zip'):
        print('Génération du ZIP : ', zip_file+'/'+ dir +'.zip')
        if not os.path.exists(zip_file):
            os.makedirs(zip_file)
        make_archive(zip_file+'/'+ dir, 'zip', working_path)


我尝试使用系统命令创建 zip,但我遇到了同样的问题:

os.system(f'zip -r -j {zip_file}/{dir}.zip {working_path}')

我也试过 try except 但没有抛出异常

我找到了答案。我的进程数量低于我的 for 循环启动的进程数量。所以如果这个进程还没有完成他的处理,它就会被一个新的进程覆盖。