Skip to content

multiprocessing.Pool map hangs #122930

Closed as not planned
Closed as not planned
@wdxal

Description

@wdxal

Bug report

Bug description:

Q:
Run the following code, sometimes subprogres that is created by [class A's Pool or class B's Pool] is going to sleeping status, and there is not any error log output.
But code(#3 or #4)run success, code(#1 or #2) is not run,The reason is pool.close() and pool.join() is not writed in source code?

test.py

from multiprocessing import Pool
import os
from test_common import *

class Test:
    def __init__(self):
        self.A = A()
        self.B = B()

    def run(self):
        data_list = list(range(10001, 11984))

        a_list = self.A.run(data_list)
        print("self.A.run end") #1

        new_list = self.B.run(data_list, a_list)
        print("self.B.run end") #2


def main():
    run_module = Test()
    run_module.run()

if __name__ == '__main__':
    main()

---------------------------------------------
test_common.py

import os
import multiprocessing
from multiprocessing import Pool
import io
import datetime
import time

class A:
    def __init__(self):
        pass

    def run(self, data_list):
        a_list = []
        for item in data_list:
            file_path = "{}/{}.aaa".format("/tmp/aaa", item)
            a_list.append(file_path)

        pool_size = 1
        pool = Pool(pool_size)
        pool.map(methodA, a_list)
        print("A#run end") #3
        return a_list


def methodA(file_path):
    if os.path.isfile(file_path):
        return
    # other code

class B:
    def __init__(self):
        pass

    def run(self, data_list, a_list):        
        b_list = []
        for item in data_list:
            b_path = "{}/{}.bbb".format("/tmp/bbb", item)
            b_list.append(b_path)

        pool_size = 1
        pool = Pool(pool_size)
        pool.map(methodB, b_list)
 
        print("B#run end") #4
        return b_list

def methodB(b_path):
    if os.path.isfile(b_path):
        return
    # other code

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy