title: how to control process in python?
body: <p>I want to run several process in parallel without giving cpu too much work so that cpu can also do other jobs.</p>
  
  <p>In python, I will use os.system to call some binary. And theses call are independent and can be parallel. But these binary may run for different length of time.</p>
  
  <p>What I want to do is for example, always keep 8 of them run in parallel, if some one exit early, then start another one.</p>
  
  <p>what I am doing now is like this:</p>
  
  <pre><code>count = 0
  for f in files:
      count = count + 1
      cmd = exe 
      if (count != 8):
          cmd = cmd + " &amp;"
      else:
          count = 0
      os.sytem(cmd)
  </code></pre>
  
  <p>but this will be not ideal if the <code>cmd</code> without &amp; runs too long or too short.</p>
  
  <p>I also tried multiprocessing module,</p>
  
  <pre><code>p=Pool(8)
  print(p.map(f,list_of_args))
  </code></pre>
  
  <p>but in this case I am not running 8 processes in parallel for most of the time. Since some of them exit early.</p>
  
  <p>There is no need for synchronization.</p>
  
  <p>I have 16 cpu cores and I want half of them(8 processes to runs in parallel) </p>