From: Eduardo Habkost Subject: Re: [KVM-AUTOTEST PATCH v2 3/6] [RFC] Introduce exception context strings Date: Wed, 5 Jan 2011 14:21:27 -0200 Message-ID: <20110105162127.GE3361@otherpad.lan.raisama.net> References: <1294242329-11034-1-git-send-email-mgoldish@redhat.com> <1294242329-11034-3-git-send-email-mgoldish@redhat.com> <4D249855.30607@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Michael Goldish , autotest@test.kernel.org, kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44743 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097Ab1AEQV3 (ORCPT ); Wed, 5 Jan 2011 11:21:29 -0500 Content-Disposition: inline In-Reply-To: <4D249855.30607@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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. -- Eduardo