python multiprocessing manager list error: [Errno 2] No such file or directory

后端 未结 1 1374
你的背包
你的背包 2020-12-28 17:21

I worte a multiprocessing program in python. I use multiprocessing.Manager().list() to share list within subprocess. At first, I add some tasks in main process.

相关标签:
1条回答
  • 2020-12-28 18:16

    The problem is that your main process is exiting immediately after you start all your worker processes, which shuts down your Manager. When your Manager shuts down, none of the children can use the shared list you passed into them. You can fix it by using join to wait for all the children to finish. Just make sure you actually start all your processes prior to calling join:

    for i in range(AMOUNT_OF_PROCESS):
        processes[i] = multiprocessing.Process(target=worker, args=())
        processes[i].start()
    for process in processes:
        process.join()
    
    0 讨论(0)
提交回复
热议问题