0

我无法成功执行以下代码,总是以以下错误结束:

OSError: [Errno 24] Too many open files
with the most recent call on p.start()

如您所见,我已经尝试以 500 个块执行进程,因为它们在仅执行 500 个时运行良好,但是在第二个循环之后我仍然收到上述错误。我猜这些进程在执行后没有正确关闭,但是我不知道如何检查并正确关闭它们......

这是我的代码:

import multiprocessing

manager = multiprocessing.Manager()
manager_lists = manager.list()


def multiprocessing_lists(a_list):
    thread_lists = []
    for r in range(400):
        thread_lists.append(a_list)
    manager_lists.extend(thread_lists)


manager = multiprocessing.Manager()
manager_lists = manager.list()
processes = []
counter = 0
chunk_size = 500
all_processes = 4000


for i in range(0, all_processes, chunk_size):

    for j in range(chunk_size):
        a_list = [1,2,3,4,5,6,7,8,9]
        p = multiprocessing.Process(target=multiprocessing_lists, args=(a_list,))
        processes.append(p)
        p.start()

        counter += 1
    for process in processes:
        process.join()
        process.terminate()


print(len(manager_lists))
4

0 回答 0