From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Goldish Subject: Re: [KVM-AUTOTEST PATCH v2 3/6] [RFC] Introduce exception context strings Date: Wed, 05 Jan 2011 20:55:44 +0200 Message-ID: <4D24BEB0.4040502@redhat.com> References: <1294242329-11034-1-git-send-email-mgoldish@redhat.com> <1294242329-11034-3-git-send-email-mgoldish@redhat.com> <4D249855.30607@redhat.com> <20110105162127.GE3361@otherpad.lan.raisama.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: autotest@test.kernel.org, Avi Kivity , kvm@vger.kernel.org To: Eduardo Habkost Return-path: In-Reply-To: <20110105162127.GE3361@otherpad.lan.raisama.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org On 01/05/2011 06:21 PM, Eduardo Habkost wrote: > On Wed, Jan 05, 2011 at 06:12:05PM +0200, Avi Kivity wrote: >> It would be nice to make the error context a stack, and to use the >> with statement to manage the stack: >> >> >> with error.context("main test"): >> foo() >> with error.context("before reboot"): >> bar() >> >> If foo() throws an exception, the context would be "main test", >> while if bar() throws an exception, the context would be "before >> reboot" in "main test". > > Autotest targets Python 2.4, and Python 2.4 doesn't have the 'with' > statement. > > The error context is already a stack, but without the 'with' statement > you would have to use try/finally explicitly: > > _new_context('foo') > try: > # [...] > finally: > _pop_context() > > By the way, I think we could make _new_context() and _pop_context() part > of the public interface (i.e. remove the "_" from their names). I see > @context_aware as just a helper for a stack interface that could be used > directly if needed. To actually use the context you also have to insert it into an exception, i.e. _new_context('foo') try: try: ... except Exception, e: e._context = get_context() finally: _pop_context() and I thought it would be more comfortable to just define a @context_aware function and call it.