2017-02-09 10 views
1

私はプールでmultiThreadedを作成したいと思う機能を持っています。クラスとメンバ関数のリストを持つThreadPool

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

入力がリストである場合にマルチスレッドのバージョンがチェックwouuld:上記のように、私はクラスのリストでpool.mapを呼び出すことができますどのように

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() 

答えて

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) 
関連する問題