为什么pool.apply_async无法使用params调用该函数?

时间:2015-02-24 22:33:22

标签: python python-multiprocessing

所以我有一个main_function,我尝试创建一个进程池,并使用apply_async函数调用另一个函数

Class Abc():
    def main_func(self):
        try:
            colo='xyz,pqr'
            colo_arr = colo.split(',')
            #Fork as many processes as colo i.e. one process/Colo
            pool = mp.Pool(len(colo_arr))
            for i in range(len(colo_arr)):
                db, host = self.findme(colo_arr[i])
                if db is None or host is None:
                    logger.exception("Exception while trying to find dbname, host for colo : %s", colo_arr[i])
                else:                                   
                    pool.apply_async(self.run_me,(colo_arr[i],))

            pool.close()
            pool.join()

        except Exception as e:
            leogger.exception("Exception while trying to find dbname, hostname for colo : %s", colo_arr[i])


  def run_me(self):
     print 'hello'

但它永远不会到达run_me函数,即使我可以看到使用ps -ef |分叉进程grep process_name。所以我不确定这些子进程是做什么的,因为它们似乎永远不会终止。

此外,如果我这样做pool.apply_async(self.run_sql(job_id, sql_text, schema, dbname, hostname, requester, colo_arr[i]))它可以工作,但它不是真正的并行,因为它不会分叉任何进程,并且与使用apply_async()调用函数一样好。

0 个答案:

没有答案