Created
December 9, 2014 17:54
-
-
Save ironpythonbot/4c6ba2c83dcb121ef071 to your computer and use it in GitHub Desktop.
CodePlex Issue #31043 Plain Text Attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
from functools import wraps | |
@contextmanager | |
def enter_stage(message): | |
# Start stage | |
print("Start '{0}' stage".format(message)) | |
try: | |
yield | |
finally: | |
# Finish stage | |
print("End '{0}' stage".format(message)) | |
def enter_stage_decorator(message): | |
def decorator(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
with enter_stage(message): | |
return func(*args, **kwargs) | |
return wrapper | |
return decorator | |
# Examples of how it is intended to use defined above managers: | |
# | |
# with enter_stage("test 1"): | |
# print " Do test 1 stuff" | |
# | |
# @enter_stage_decorator("test 2") | |
# def test_2(x): | |
# print " Do test 2 stuff (x = {0})".format(x) | |
# | |
# test_2(30) | |
# Bug is rising below: | |
@enter_stage_decorator("test") | |
def test(): | |
print " test() call f()" | |
f() | |
print " f() is done" # never reached | |
def f(): | |
print " f() call g()" | |
g() | |
def g(): | |
print " g() raise exception now" | |
raise Exception("some exception") | |
try: | |
test() | |
except: | |
import traceback | |
traceback.print_exc() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment