Python Multiprocessing Script Freezes Seemingly Without Error

前端 未结 1 1722
一整个雨季
一整个雨季 2021-01-19 17:23

I am trying to use the multiprocessing package to call a function (let\'s call it myfunc) in parallel, specifically using pool.map i.e

相关标签:
1条回答
  • 2021-01-19 18:02

    Check whether all the processes are started or not.This will help you to debug it.Also add Pool.join() at the end of your code.

    This is a sample code

    def start_process():
        print 'Starting', multiprocessing.current_process().name
    
    if __name__ == '__main__':
    
        pool_size =2
        pool = multiprocessing.Pool(processes=pool_size,
                                    initializer=start_process,
                                    )
    
        pool_outputs = pool.map(function_name,argument_list)
        pool.close() # no more tasks
        pool.join()  # wrap up current tasks
    
    0 讨论(0)
提交回复
热议问题