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.65; helo=mga03.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel-bounces@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 F3EE321189FBF; Thu, 1 Nov 2018 19:18:51 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2018 19:18:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,454,1534834800"; d="scan'208";a="82799241" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga007.fm.intel.com with ESMTP; 01 Nov 2018 19:18:51 -0700 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 1 Nov 2018 19:18:50 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 1 Nov 2018 19:18:50 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.102]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.214]) with mapi id 14.03.0415.000; Fri, 2 Nov 2018 10:18:49 +0800 From: "Feng, Bob C" To: edk2-devel , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: [edk2] [PATCH v3 1/1] BaseTools: Explicitly close files after readlines Thread-Index: AQHUclAsgJCCn+0n20qn+W/cp5VwB6U7v66w Date: Fri, 2 Nov 2018 02:18:48 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D15FFF4375@SHSMSX101.ccr.corp.intel.com> References: <20181102020210.12320-1-michael.johnson@intel.com> In-Reply-To: <20181102020210.12320-1-michael.johnson@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZTFmODhlYWQtYjRkZi00NzU4LTgzZjAtODFiN2Q2ZTAzYzVlIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiQmIyaVlMcVZpbUhZQ3dxRG02cHpiVEs5U3YwUVJQUU1TdzB6M1hcL0V2SDVHZ3ZcL3dYWUZ6WGdmdEhGSmZBdFZCIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 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 02:18:52 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob C Feng =20 Thanks, Bob -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org]=20 Sent: Friday, November 2, 2018 10:02 AM To: edk2-devel@lists.01.org Cc: Gao, Liming Subject: [edk2] [PATCH v3 1/1] BaseTools: Explicitly close files after read= lines 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/So= urce/Python/Workspace/MetaFileParser.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/InfSectionParser.py b/BaseTool= s/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 =3D [] =20 try: - FileLinesList =3D open(self._FilePath, "r", 0).readlines() + with open(self._FilePath, "r", 0) as File: + FileLinesList =3D File.readlines() except BaseException: EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened fai= led.' % self._FilePath) =20 diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/Source/Python/Workspace/MetaFileParser.py index 804a4aa5cb..1cbed6e693 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -537,7 +537,8 @@ class InfParser(MetaFileParser): NmakeLine =3D '' Content =3D '' try: - Content =3D open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content =3D File.readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=3Dself.= MetaFile) =20 @@ -917,7 +918,8 @@ class DscParser(MetaFileParser): def Start(self): Content =3D '' try: - Content =3D open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content =3D File.readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=3Dself.= MetaFile) =20 @@ -1429,7 +1431,12 @@ class DscParser(MetaFileParser): self._SubsectionType =3D MODEL_UNKNOWN =20 def __RetrievePcdValue(self): - Content =3D open(str(self.MetaFile), 'r').readlines() + try: + with open(str(self.MetaFile), 'r') as File: + Content =3D File.readlines() + except: + EdkLogger.error("Parser", FILE_READ_FAILURE,=20 + ExtraData=3Dself.MetaFile) + GlobalData.gPlatformOtherPcds['DSCFILE'] =3D str(self.MetaFile) for PcdType in (MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_D= EFAULT, MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_DEFAUL= T, MODEL_PCD_DYNAMIC_EX_HII, @@ -1727,7 +1734,8 @@ class DecParser(MetaFile= Parser): def Start(self): Content =3D '' try: - Content =3D open(str(self.MetaFile), 'r').readlines() + with open(str(self.MetaFile), 'r') as File: + Content =3D File.readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=3Dself.= MetaFile) =20 -- 2.18.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel