From nobody Sun Feb 8 22:34:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+44934+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+44934+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1565075731; cv=none; d=zoho.com; s=zohoarc; b=fdXD+uZsRcb4SeFXP3iE70K5qPEEnchA9+3ug1zTXjeRmlaj5QHTkP6ynehtKoPvom3SPm1lXNWJ4B2DsoP1gBcTcesdonNvpVD1E2ZFl+JQW0n9DXRWDME4ObNLP7NC0Bg2uSsIWKgqmX0NfD/z+3sBWW0mjcm9Xtjxsmuivxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565075731; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=Skkfr3XUCW8ONXRdTREdEG1Dteqhi2V/AqOsaciULPY=; b=T+OdQ7Y9qs2vui8oCL8ZjtaVIv5oKAnsj3f/5jNRurcAxT9WNIpMtKpsAeTnhpJ9CqfkgS9pWqYYg6nfZJgJx5JhEKDRa5AYX1rTYUMexlaijQRnPJE9SqMoO1BdLtD1wJQRD0C7iM8/BWdFnAxWn8HW/8RZI7aj9TPTBnVwTvg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+44934+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1565075731349470.6694525445895; Tue, 6 Aug 2019 00:15:31 -0700 (PDT) Return-Path: X-Received: from mga05.intel.com (mga05.intel.com []) by groups.io with SMTP; Tue, 06 Aug 2019 00:15:30 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 00:15:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,352,1559545200"; d="scan'208";a="325551478" X-Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.47]) by orsmga004.jf.intel.com with ESMTP; 06 Aug 2019 00:15:29 -0700 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Bob Feng Subject: [edk2-devel] [Patch 09/10 V7] BaseTools: Add the support for python 2 Date: Tue, 6 Aug 2019 15:15:10 +0800 Message-Id: <20190806071511.11836-10-bob.c.feng@intel.com> In-Reply-To: <20190806071511.11836-1-bob.c.feng@intel.com> References: <20190806071511.11836-1-bob.c.feng@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,bob.c.feng@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1565075731; bh=93BamqC9wh/1Dm0fNKUutt3X8dAKXW8tWeFdNUm1fkQ=; h=Cc:Date:From:Reply-To:Subject:To; b=YVm0IHXpDr7ufl66UCLeSYS4o+bptatAfbAjtY67Ti4sDbyG0cWSJEGjB3ue0nIwEMu 7QDZ4pBvgPHoz8m1uRPVLOk7pcpygtUZBk3QAbYjHC9PAEotiNNo2K8nq52C0XnnxW3kQ gcMKhgVxka8t2xTBVJhRNwd+WLKSxAZRD3Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1875 python3 change the module name of Queue to queue. python3 add a new log handler of QueueHandler. This patch is to make Multiple process AutoGen feature work for python2 Cc: Liming Gao Signed-off-by: Bob Feng --- .../Source/Python/AutoGen/AutoGenWorker.py | 5 +- BaseTools/Source/Python/Common/EdkLogger.py | 92 ++++++++++++++++++- 2 files changed, 92 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGenWorker.py b/BaseTools/S= ource/Python/AutoGen/AutoGenWorker.py index 1296604f688d..0a3c1d8e0ebd 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGenWorker.py +++ b/BaseTools/Source/Python/AutoGen/AutoGenWorker.py @@ -14,11 +14,14 @@ import Common.GlobalData as GlobalData import Common.EdkLogger as EdkLogger import os from Common.MultipleWorkspace import MultipleWorkspace as mws from AutoGen.AutoGen import AutoGen from Workspace.WorkspaceDatabase import BuildDB -from queue import Empty +try: + from queue import Empty +except: + from Queue import Empty import traceback import sys from AutoGen.DataPipe import MemoryDataPipe def clearQ(q): try: diff --git a/BaseTools/Source/Python/Common/EdkLogger.py b/BaseTools/Source= /Python/Common/EdkLogger.py index f6a5e3b4daf9..15fd1458a95a 100644 --- a/BaseTools/Source/Python/Common/EdkLogger.py +++ b/BaseTools/Source/Python/Common/EdkLogger.py @@ -3,16 +3,100 @@ # # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 +# Copyright 2001-2016 by Vinay Sajip. All Rights Reserved. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, +# provided that the above copyright notice appear in all copies and that +# both that copyright notice and this permission notice appear in +# supporting documentation, and that the name of Vinay Sajip +# not be used in advertising or publicity pertaining to distribution +# of the software without specific, written prior permission. +# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLU= DING +# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES= OR +# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHET= HER +# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING O= UT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# This copyright is for QueueHandler. + ## Import modules from __future__ import absolute_import import Common.LongFilePathOs as os, sys, logging import traceback from .BuildToolError import * -import logging.handlers +try: + from logging.handlers import QueueHandler +except: + class QueueHandler(logging.Handler): + """ + This handler sends events to a queue. Typically, it would be used = together + with a multiprocessing Queue to centralise logging to file in one = process + (in a multi-process application), so as to avoid file write conten= tion + between processes. + + This code is new in Python 3.2, but this class can be copy pasted = into + user code for use with earlier Python versions. + """ + + def __init__(self, queue): + """ + Initialise an instance, using the passed queue. + """ + logging.Handler.__init__(self) + self.queue =3D queue + + def enqueue(self, record): + """ + Enqueue a record. + + The base implementation uses put_nowait. You may want to overr= ide + this method if you want to use blocking, timeouts or custom qu= eue + implementations. + """ + self.queue.put_nowait(record) + + def prepare(self, record): + """ + Prepares a record for queuing. The object returned by this met= hod is + enqueued. + + The base implementation formats the record to merge the message + and arguments, and removes unpickleable items from the record + in-place. + + You might want to override this method if you want to convert + the record to a dict or JSON string, or send a modified copy + of the record while leaving the original intact. + """ + # The format operation gets traceback text into record.exc_text + # (if there's exception data), and also returns the formatted + # message. We can then use this to replace the original + # msg + args, as these might be unpickleable. We also zap the + # exc_info and exc_text attributes, as they are no longer + # needed and, if not None, will typically not be pickleable. + msg =3D self.format(record) + record.message =3D msg + record.msg =3D msg + record.args =3D None + record.exc_info =3D None + record.exc_text =3D None + return record + + def emit(self, record): + """ + Emit a record. + + Writes the LogRecord to the queue, preparing it for pickling f= irst. + """ + try: + self.enqueue(self.prepare(record)) + except Exception: + self.handleError(record) =20 ## Log level constants DEBUG_0 =3D 1 DEBUG_1 =3D 2 DEBUG_2 =3D 3 @@ -206,23 +290,23 @@ def LogClientInitialize(log_q): # Since we use different format to log different levels of message int= o different # place (stdout or stderr), we have to use different "Logger" objects = to do this. # # For DEBUG level (All DEBUG_0~9 are applicable) _DebugLogger.setLevel(INFO) - _DebugChannel =3D logging.handlers.QueueHandler(log_q) + _DebugChannel =3D QueueHandler(log_q) _DebugChannel.setFormatter(_DebugFormatter) _DebugLogger.addHandler(_DebugChannel) =20 # For VERBOSE, INFO, WARN level _InfoLogger.setLevel(INFO) - _InfoChannel =3D logging.handlers.QueueHandler(log_q) + _InfoChannel =3D QueueHandler(log_q) _InfoChannel.setFormatter(_InfoFormatter) _InfoLogger.addHandler(_InfoChannel) =20 # For ERROR level _ErrorLogger.setLevel(INFO) - _ErrorCh =3D logging.handlers.QueueHandler(log_q) + _ErrorCh =3D QueueHandler(log_q) _ErrorCh.setFormatter(_ErrorFormatter) _ErrorLogger.addHandler(_ErrorCh) =20 ## Set log level # --=20 2.20.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#44934): https://edk2.groups.io/g/devel/message/44934 Mute This Topic: https://groups.io/mt/32740906/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-