from multiprocessing import Pool def a(num): print num if __name__ == "__main__": pool = Pool(3) for i in range(10): pool.apply_async(a,args=(i,)) pool.close() pool.join()
用进程池运行a这个函数,返回结果是正常的,但是假如这么写:
from multiprocessing import Pool class adb(): def a(self,num): print num if __name__ == "__main__": pool = Pool(3) for i in range(10): pool.apply_async(adb().a,args=(i,)) pool.close() pool.join()
则程序没有任何返回就结束了,请问这是怎么回事呢,有什么办法让后面这种写法也可以运行呢?
pool.apply_async(adb().a,args=(i,))
一周热门 更多>