title: Python - Running many different types of threads without exhausting resources
body: <p>I am attempting to do some clean multi-threading but maybe my approach is wrong.</p>
  
  <p>I have a <code>BaseFix</code> Thread class with 6 different types of children, one of which is <code>CommandFix</code> Thread, another is <code>ParamFix</code> Thread.</p>
  
  <p>Their <code>run</code> functions have different code inside them, but will mostly utilize the <code>subprocess.run</code> function.</p>
  
  <pre><code>class CommandFix(BaseFix):
  
      def __init__(self, group=None, target=None, name=None,
               args=(), kwargs=None, verbose=None):
  
          super(CommandFix, self).__init__(group=group, target=target, 
                        name=name, kwargs=kwargs, verbose=None)
  
  
      def _execute_command(self):
          self.stdout_log.write("fixing {} : running command {}".format(
              self.rule_id,
              self.command))
  
          try:
              cp = subprocess.run(self.command,
                  shell=True, check=True,
                  stdout=self.stdout_log,
                  stderr=self.stderr_log
                  )
          except subprocess.CalledProcessError as e:
              self.stderr_log.write("error fixing {} : {}".format(
                  self.rule_id,
                  e))
  
              # TO-DO: Handle error with retry or similar
              # right now just return false
              return False
  
          return True
  
      def _verify_command(self):
          pass
  
      def run(self):
  
          # execute the command
          if self._execute_command():
              # now run the verification
              pass
          else:
              # TO-DO: error handling
              pass
  </code></pre>
  
  <p>I have about <code>200</code> fixes of about <code>6</code> different types.  I am checking their fix type, then instantiating the required Fix and calling <code>run</code> like so:</p>
  
  <pre><code>def _fix(key, rule):
      expr = "./{}fixtext".format(NS)
      fixtext = rule.find(expr)
  
      expr = "./{}div".format(NS1)
      fixtext = fixtext.find(expr).getchildren()[0].getchildren()[0].text
  
      if fixtext.find('Run the following command') &gt; 0:
          fix = CommandFix(rule, stdout_log, stderr_log, key)
  
      elif fixtext.find('Set the following') &gt; 0:
          # fix = SomeOtherFix()
          pass
  
      elif fixtext.find('For 32 bit systems') &gt; 0:
          # fix = SomeOtherKindOfFix()
          pass
  
      fix.run()
  
  # there are only 200 but assume there are 2 million
  for key, rule in rules.items():
      _fix(key, rule)
  </code></pre>
  
  <p>What I would like to do is clean this up so that I am only executing <code>X number of fixes</code> at one time so that I don't exhaust the system's resources.</p>