multithreading - python multiprocessing handling an array of numbers concurrently -


i have list of number:

a=[1,2,3,4,5,.....2000] 

i have square each number , update same array, instead of writing loop want using parallel processing.

so squaring each number in array becomes process in itself.

expected output=[1,3,9,16,25,........] 

how can achieve python multiprocessing library?

already tried use threading library code not fast enough, plus threading library not using cores.

you can use pool class multiprocessing module

from multiprocessing import pool  def f(x):     return x*x  if __name__ == '__main__':     p = pool(5)     print(p.map(f, [1, 2, 3]))  #prints [1, 4, 9] 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -