From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=michael.johnson@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B837221188C50 for ; Thu, 1 Nov 2018 16:36:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2018 16:36:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,454,1534834800"; d="scan'208";a="277652345" Received: from mjohn4-mobl.amr.corp.intel.com ([10.241.246.59]) by fmsmga006.fm.intel.com with ESMTP; 01 Nov 2018 16:36:16 -0700 From: Michael Johnson To: edk2-devel@lists.01.org Cc: mjohn4 , Liming Gao Date: Thu, 1 Nov 2018 16:35:20 -0700 Message-Id: <20181101233520.908-1-michael.johnson@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Subject: [PATCH v1 1/1] BaseTools: Explicitly close files after readlines X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Nov 2018 23:36:16 -0000 From: mjohn4 Rework some file open().readlines to open, readlines, close. This prevents excessive file handles being open at the same time, which may be a problem with alternative python environments. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael Johnson --- BaseTools/Source/Python/AutoGen/InfSectionParser.py | 4 +++- BaseTools/Source/Python/Workspace/MetaFileParser.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/InfSectionParser.py b/BaseTools/Source/Python/AutoGen/InfSectionParser.py index d985089738..b186984101 100644 --- a/BaseTools/Source/Python/AutoGen/InfSectionParser.py +++ b/BaseTools/Source/Python/AutoGen/InfSectionParser.py @@ -34,7 +34,9 @@ class InfSectionParser(): SectionData = [] try: - FileLinesList = open(self._FilePath, "r", 0).readlines() + File = open(self._FilePath, "r", 0) + FileLinesList = File.readlines() + File.close() except BaseException: EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened failed.' % self._FilePath) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 804a4aa5cb..9a795315d1 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -537,7 +537,9 @@ class InfParser(MetaFileParser): NmakeLine = '' Content = '' try: - Content = open(str(self.MetaFile), 'r').readlines() + File = open(str(self.MetaFile), 'r') + Content = File.readlines() + File.close () except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) @@ -917,7 +919,9 @@ class DscParser(MetaFileParser): def Start(self): Content = '' try: - Content = open(str(self.MetaFile), 'r').readlines() + File = open(str(self.MetaFile), 'r') + Content = File.readlines() + File.close() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) @@ -1429,7 +1433,9 @@ class DscParser(MetaFileParser): self._SubsectionType = MODEL_UNKNOWN def __RetrievePcdValue(self): - Content = open(str(self.MetaFile), 'r').readlines() + File = open(str(self.MetaFile), 'r') + Content = File.readlines() + File.close() GlobalData.gPlatformOtherPcds['DSCFILE'] = str(self.MetaFile) for PcdType in (MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_DYNAMIC_EX_HII, @@ -1727,7 +1733,9 @@ class DecParser(MetaFileParser): def Start(self): Content = '' try: - Content = open(str(self.MetaFile), 'r').readlines() + File = open(str(self.MetaFile), 'r') + Content = File.readlines() + File.close() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) -- 2.18.0.windows.1