title: how can restrict processes in parallel
body: <p>I have this script, but I only want to start 3 perl processes at a time. Once these 3 are done, the script should start the next three.</p>
  
  <p>at the moment all processes are started in parallel</p>
  
  <p>unfortunately I don't know what to do. can someone help me?</p>
  
  <p>my script:</p>
  
  <pre><code>import json, os
  import subprocess
  from subprocess import Popen, PIPE
  
  list = open('list.txt', 'r')
  
  
  procs = []
  for dirs in list:
      args = ['perl', 'test.pl', '-a', dirs]
      proc = subprocess.Popen(args)
          procs.append(proc)
  
  for proc in procs:
     proc.wait()
  </code></pre>
  
  <p>list.txt :</p>
  
  <pre><code>dir1
  dir2
  dir3
  dir4
  dir5
  dir6
  dir7
  dir8
  dir9
  dir10
  dir11
  </code></pre>
  
  <p>test.pl</p>
  
  <pre><code>$com=$ARGV[0];
  $dirs=$ARGV[1];
  print "$com $dirs";
  sleep(5);
  </code></pre>