def iterate_gists_to_archive(self, gists: List[Gist.Gist], operation: str) -> List[Optional[str]]: """Iterate over each gist and start a thread if it can be archived.""" pool = ThreadPoolExecutor(self.threads) thread_list = [] for gist in gists: gist_path = os.path.join(self.location, 'gists', gist.id) thread_list.append( pool.submit( self.archive_gist, gist=gist, gist_path=gist_path, operation=operation, ) ) wait(thread_list, return_when=ALL_COMPLETED) failed_gists = [gist.result() for gist in thread_list if gist.result()] return failed_gists