Package grassyknoll :: Package concurrent :: Module Fault
[hide private]

Source Code for Module grassyknoll.concurrent.Fault

 1  """contains L{Fault}""" 
 2   
 3  import sys 
 4  import traceback 
 5  from functools import partial 
 6   
 7  import Message 
 8   
 9  __all__=['Fault', 'current_tb_message'] 
10   
11  # XXX this is basically identical to CrashError 
12 -class Fault(object):
13 """handy encapsulation of an exception 14 15 @ivar type: the type of the exception 16 @type type: type 17 18 @ivar value: the exception instance 19 @type value: instance 20 21 @ivar traceback: a stringified traceback that produced the exception. May 22 be None 23 @type traceback: traceback 24 """ 25 __slots__=['type', 'value', 'traceback'] 26
27 - def __init__(self, etype, value, tb=None):
28 self.type=etype 29 self.value=value 30 if tb is not None: 31 self.traceback="".join(traceback.format_exception(etype, value, tb)) 32 else: 33 self.traceback=None
34
35 -def current_tb_message(re_id=None, reply_box=None, include_tb=False):
36 """create a message from the current exception 37 38 @arg re_id: the id of the message this is a response to 39 @type re_id: L{Messsage.id} 40 41 @ivar reply_box: where responses for this message should be 42 sent to. May be None. 43 @type reply_box: L{MailBox.MailBox} 44 45 @arg include_tb: should a stringified traceback of the current exception 46 @be included in the L{Fault} 47 @type include_tb: Boolean 48 """ 49 50 m = (partial(Message.Message, re_id=re_id) if re_id is not None 51 else Message.Message) 52 53 return m(Fault(*(sys.exc_info()[:3 if include_tb else 2])), 54 reply_box=reply_box)
55