为什么python多处理异步不调用函数

时间:2018-04-29 04:52:48

标签: python multiprocessing pool

我开始使用多处理但是我遇到了池的问题因为没有调用我的函数,我找不到#Case C中哪个错了,其他情况没有问题,在我的代码下面:

import imp
import multiprocessing as mp

mysql_q_mps = imp.load_source('mysql_q_mps', '\\path\\get_query_mps.py')

if __name__ ==  '__main__':

    def get_query_ps(tipo,sql_info,log_filename):
        pool = mp.Pool()      
        cola_logfile=mp.Queue()


        idx_ps = 1

        # Case A, This one works#
        mysql_q_mps.get_query_sps(tipo,sqls_exe,idx_ps,cola_logfile)

        # Case B, This one works#
        cola_1=mp.Process(target=mysql_q_mps.get_query_sps,args=(tipo,sqls_exe,idx_ps,cola_logfile))
        cola_1.start()   

        # Case C, This one does not works#
        pool.apply_async(mysql_q_mps.get_query_sps,(tipo,sqls_exe,idx_ps,cola_logfile)) 

        return    

    log_path='//pathlogfile'
    sqls_exe = 'SQLQuery'

    get_query_ps('exe',sqls_exe,log_path)

0 个答案:

没有答案