title: python multithreading with os system, no more than K parallel commands
body: <p>Regarding the following example:</p>
  <pre><code>import os
  NUM_CPUS = None  # defaults to all available
  
  def worker(f1, f2):
      os.system(&quot;run program x on f1 and f2&quot;) &lt;--- Big command, cannot run more that K in parallel
  
  def test_run(pool):
       filelist = os.listdir(files_dir)
       for f1 in filelist:
            for f2 in filelist:
                 pool.apply_async(worker, args=(f1, f2))
  
  if __name__ == &quot;__main__&quot;:
       import multiprocessing as mp
       pool = mp.Pool(NUM_CPUS)
       test_run(pool)
       pool.close()
       pool.join()
  </code></pre>
  <p>Each <code>os.system</code> call consumes a lot of resources thus I cannot dispatch more than K(<code>5</code>) in parallel.
  Unfortunately, even when settings <code>NUM_POOLS=5</code> each <code>pool.apply_async</code> returns immedietly.
  How can I specify python not to let more than 5 workers run in parallel?</p>