'Update queue'

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):
                    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)
    if DEBUG_EDITOR:
        print('Updating    queue:', file=STDOUT)
        print('                started:', started, file=STDOUT)
        print('                pending:', len(self.pending_threads), file=STDOUT)
    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])
        if DEBUG_EDITOR:
            print('===>starting:', thread, file=STDOUT)
        thread.start()
