From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=michael.johnson@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 C4C3821173C7D for ; Thu, 1 Nov 2018 18:14:32 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2018 18:14:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,454,1534834800"; d="scan'208";a="100817647" Received: from mjohn4-mobl.amr.corp.intel.com ([10.241.246.59]) by fmsmga002.fm.intel.com with ESMTP; 01 Nov 2018 18:14:22 -0700 From: Michael Johnson To: edk2-devel@lists.01.org Cc: mjohn4 , Liming Gao Date: Thu, 1 Nov 2018 18:13:24 -0700 Message-Id: <20181102011324.13096-1-michael.johnson@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Subject: [PATCH v2 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: Fri, 02 Nov 2018 01:14:32 -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 | 3 ++- BaseTools/Source/Python/Workspace/MetaFileParser.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/InfSectionParser.py b/BaseTools/Source/Python/AutoGen/InfSectionParser.py index d985089738..69f0bc8ee9 100644 --- a/BaseTools/Source/Python/AutoGen/InfSectionParser.py +++ b/BaseTools/Source/Python/AutoGen/InfSectionParser.py @@ -34,7 +34,8 @@ class InfSectionParser(): SectionData = [] try: - FileLinesList = open(self._FilePath, "r", 0).readlines() + with open(self._FilePath, "r", 0) as File: + FileLinesList = File.readlines() 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..374886b8b6 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -537,7 +537,8 @@ class InfParser(MetaFileParser): NmakeLine = '' Content = '' try: - Content = open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content = File.readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) @@ -917,7 +918,8 @@ class DscParser(MetaFileParser): def Start(self): Content = '' try: - Content = open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content = File.readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) @@ -1429,7 +1431,8 @@ class DscParser(MetaFileParser): self._SubsectionType = MODEL_UNKNOWN def __RetrievePcdValue(self): - Content = open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content = File.readlines() 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 +1730,8 @@ class DecParser(MetaFileParser): def Start(self): Content = '' try: - Content = open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content = File.readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) -- 2.18.0.windows.1