2017-11-09 10 views
0
# coding: utf-8 

import multiprocessing 


class A(object): 

    def __init__(self): 
     pass 

    def run(self): 
     sheets = ['a', 'b', 'c', 'd', 'e'] 
     result = [] 

     pool = multiprocessing.Pool(processes=5) 

     for index, sheet in enumerate(sheets): 
      result.append(pool.apply_async(self.test, (sheet))) 

     pool.close() 
     pool.join() 

     for data in result: 
      print data.get() 

    def test(self, args): 
     return args 


if __name__ == '__main__': 
    A().run() 

피클 수 없습니다 수 없습니다 피클 : 속성 조회를 내장 .instancemethod failed파이썬 멀티는 <유형 'instancemethod'> 내가 답변을 얻을 수 있었으면, 오류가 위의 코드를 실행하고 얻으려고

답변

0
# coding: utf-8 

import multiprocessing 

def proxy(cls_instance, args): 
    return cls_instance.test(args) 


class A(object): 

    def __init__(self): 
     pass 

    def run(self): 
     sheets = ['a', 'b', 'c', 'd', 'e'] 
     result = [] 

     pool = multiprocessing.Pool(processes=5) 

     for index, sheet in enumerate(sheets): 
      result.append(pool.apply_async(proxy, (self, sheet))) 

     pool.close() 
     pool.join() 

     for data in result: 
      print data.get() 

    def test(self, args): 
     return args 


if __name__ == '__main__': 
    A().run()