from google.cloud import storage from concurrent.futures import ThreadPoolExecutor class GCS: def __init__(self, bucket_name,project): self.bucket_name = bucket_name self.client = storage.Client(project) def get_file(self, filename): bucket = self.client.get_bucket(self.bucket_name) blob = storage.Blob(filename, bucket) return blob.download_as_text() def get_file_list(self, path): blobs = self.client.list_blobs(self.bucket_name, prefix=path) return [blob.name for blob in blobs] def file_exists(self, path): bucket = self.client.get_bucket(self.bucket_name) blob = storage.Blob(path, bucket) return blob.exists() def get_files(max_thread,project,bucket_name,filelist): resultfiles =[] with ThreadPoolExecutor(max_workers=max_thread) as executor: # The order of the exector results is the same as the order of the input, so we can guarantee the chronological order of the returned slowlogs res = executor.map(GCS.get_file, [GCS(bucket_name,project)] * len(filelist), filelist) for one in res: resultfiles.append(one) return resultfiles