title: ThreadPool and Pool for parallel processing
body: <p>Is there a way to use both ThreadPool and Pool in python to parallelise a loop by specifying the number of CPUs and cores you  wish to use?</p>
  
  <p>For example I would have a loop execute as:</p>
  
  <pre><code>from multiprocessing.dummy import Pool as ThreadPool 
  from tqdm import tqdm
  import numpy as np
  
  def my_function(x):
      return x + 1
  
  pool = ThreadPool(4)
  my_array = np.arange(0,1e6,1)
  
  
  results = list(tqdm(pool.imap(my_function, my_array),total=len(my_array)))
  </code></pre>
  
  <p>For 4 cores but it I wanted to spread these out on multiple CPUs as well, is there a simple way to adapt the code?</p>