1+ import gc
12import os
23import shutil
34import logging
@@ -47,7 +48,7 @@ def is_osw_valid(self, max_errors) -> ValidationResult:
4748 else :
4849 result .validation_message = 'Failed to validate because unknown file format'
4950 logger .error (f' Failed to validate because unknown file format' )
50-
51+ gc . collect ()
5152 return result
5253
5354 # Downloads the single file into a unique directory
@@ -56,15 +57,15 @@ def download_single_file(self, file_upload_path=None) -> str:
5657 unique_id = self .get_unique_id ()
5758 if not is_exists :
5859 os .makedirs (DOWNLOAD_FILE_PATH )
59- unique_directory = os .path .join (DOWNLOAD_FILE_PATH ,unique_id )
60+ unique_directory = os .path .join (DOWNLOAD_FILE_PATH , unique_id )
6061 if not os .path .exists (unique_directory ):
6162 os .makedirs (unique_directory )
62-
63+
6364 file = self .storage_client .get_file_from_url (self .container_name , file_upload_path )
6465 try :
6566 if file .file_path :
6667 file_path = os .path .basename (file .file_path )
67- local_download_path = os .path .join (unique_directory ,file_path )
68+ local_download_path = os .path .join (unique_directory , file_path )
6869 with open (local_download_path , 'wb' ) as blob :
6970 blob .write (file .get_stream ())
7071 logger .info (f' File downloaded to location: { local_download_path } ' )
@@ -74,14 +75,14 @@ def download_single_file(self, file_upload_path=None) -> str:
7475 except Exception as e :
7576 traceback .print_exc ()
7677 logger .error (e )
78+ finally :
79+ gc .collect ()
7780
7881 # Generates a unique string for directory
7982 def get_unique_id (self ) -> str :
8083 unique_id = uuid .uuid1 ().hex [0 :24 ]
8184 return unique_id
8285
83-
84-
8586 @staticmethod
8687 def clean_up (path ):
8788 if os .path .isfile (path ):
@@ -91,3 +92,4 @@ def clean_up(path):
9192 # folder = os.path.join(DOWNLOAD_FILE_PATH, path)
9293 logger .info (f' Removing Folder: { path } ' )
9394 shutil .rmtree (path , ignore_errors = False )
95+ gc .collect ()
0 commit comments