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. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html