Python Multiprocessing - apply class method to a list of objects

后端 未结 2 1604
夕颜
夕颜 2020-12-28 20:41

Is there a simple way to use Multiprocessing to do the equivalent of this?

for sim in sim_list:
  sim.run()

where the elements of sim_list

2条回答
  •  有刺的猬
    2020-12-28 21:08

    For those who will be working with large data sets, an iterable would be your solution here:

    import multiprocessing as mp
    pool = mp.Pool(mp.cpu_count())
    pool.imap(sim.start, sim_list)
    

提交回复
热议问题