File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import sys
33
44
5- @contextmanager
6- def panic ( log = None ):
5+ class panic ( object ):
76 """
87 The Python idiom for reraising a primary exception fails when the except block raises a
98 secondary exception, e.g. while trying to cleanup. In that case the original exception is
@@ -21,13 +20,18 @@ def panic( log=None ):
2120 If a logging logger is passed to panic(), any secondary Exception raised within the with
2221 block will be logged. Otherwise those exceptions are swallowed. At the end of the with block
2322 the primary exception will be reraised.
24-
2523 """
26- exc_type , exc_value , traceback = sys .exc_info ( )
27- try :
28- yield
29- except Exception as e :
30- if log is not None :
31- log .warn ( "Exception during panic" , exc_info = True )
32- finally :
24+
25+ def __init__ ( self , log = None ):
26+ super ( panic , self ).__init__ ( )
27+ self .log = log
28+ self .exc_info = None
29+
30+ def __enter__ ( self ):
31+ self .exc_info = sys .exc_info ( )
32+
33+ def __exit__ ( self , * exc_info ):
34+ if self .log is not None :
35+ self .log .warn ( "Exception during panic" , exc_info = exc_info )
36+ exc_type , exc_value , traceback = self .exc_info
3337 raise exc_type , exc_value , traceback
Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ def __repr__( self ):
210210 return "%s bound to %s" % (super ( BoundInner , self ).__repr__ ( ), repr ( _outer ))
211211
212212 BoundInner .__name__ = self .inner_class .__name__
213+ BoundInner .__module__ = self .inner_class .__module__
213214 return BoundInner
214215
215216 def __call__ ( * args , ** kwargs ):
You can’t perform that action at this time.
0 commit comments