code: def update_queue(self):
          
          started = 0
          for parent_id, threadlist in list(self.started_threads.items()):
              still_running = []
              for thread in threadlist:
                  if thread.isFinished():
                      end_callback = self.end_callbacks.pop(id(thread))
                      if thread.results is not None:
                          #  The thread was executed successfully
                          end_callback(thread.results)
                      thread.setParent(None)
                      thread = None
                  else:
                      still_running.append(thread)
                      started += 1
              threadlist = None
              if still_running:
                  self.started_threads[parent_id] = still_running
              else:
                  self.started_threads.pop(parent_id)
          logger.debug("Updating queue:")
          logger.debug("    started: %d" % started)
          logger.debug("    pending: %d" % len(self.pending_threads))
          if self.pending_threads and started < self.max_simultaneous_threads:
              thread, parent_id = self.pending_threads.pop(0)
              thread.finished.connect(self.update_queue)
              threadlist = self.started_threads.get(parent_id, [])
              self.started_threads[parent_id] = threadlist+[thread]
              logger.debug("===>starting: %r" % thread)
              thread.start()
docs: Update queue