2017-02-09 3 views
1

У меня есть функция, которую я хотел бы сделать multiThreaded с пулом.ThreadPool со списком классов и функцией-членом

def find(item): 
    curve=Curve(item) 
    return curve._find() 

Многопоточная версия wouuld проверить, если входной список:

def find(item): 
    if type(item) == list: 
    items=item 
    pool = ThreadPool(len(items)) 
    curves = pool.map(Curve, moniker) 
    pool.close() 

    pool = ThreadPool(len(items)) 

    # now comes the tricky part: 
    results = pool.map(???) # curves is a list of class 
          # with each having _find as a function 

    pool.close() 
    return results 

    else: 
     curve=Curve(item) 
     return curve._find() 

Как я могу позвонить pool.map со списком классов, как описано выше?

ответ

1

Если я так понимаю, вам просто нужно объявить функцию для отображения над элементами списка:

def find(item): 
    def find_(item): 
     curve=Curve(item) 
     return curve._find() 
    if type(item) == list: 
     items=item 

     pool = ThreadPool(len(items)) 

     # now comes the tricky part: 
     results = pool.map(find_, items) # curves is a list of class 
              # with each having _find as a function 

     pool.close() 
     return results 

    else: 
     return find_(item) 
Смежные вопросы