'Close threads associated to parent_id'

def close_threads(self, parent):

    if DEBUG_EDITOR:
        print("Call    to    'close_threads'", file=STDOUT)
    if (parent is None):
        self.pending_threads = []
        threadlist = []
        for threads in list(self.started_threads.values()):
            threadlist += threads
    else:
        parent_id = id(parent)
        self.pending_threads = [(_th, _id) for (_th, _id) in self.pending_threads if (_id != parent_id)]
        threadlist = self.started_threads.get(parent_id, [])
    for thread in threadlist:
        if DEBUG_EDITOR:
            print(('Waiting    for    thread    %r    to    finish' % thread), file=STDOUT)
        while thread.isRunning():
            QApplication.processEvents()
