2 shared types, functions and constants
\r
9 def raise_exception(typ, val, tbtext):
\r
10 """a helper for raising remote exceptions"""
\r
11 if type(typ) == str:
\r
14 val._remote_traceback = tbtext
\r
17 class ImmDict(object):
\r
18 """immutable dict (passes by value)"""
\r
19 def __init__(self, dict):
\r
22 return self.dict.items()
\r
24 class AttrFrontend(object):
\r
25 """a wrapper that implements the attribute protocol for a dict backend"""
\r
26 def __init__(self, dict):
\r
27 self.__dict__["____dict"] = dict
\r
28 def __delattr__(self, name):
\r
29 del self.__dict__["____dict"][name]
\r
30 def __getattr__(self, name):
\r
31 return self.__dict__["____dict"][name]
\r
32 def __setattr__(self, name, value):
\r
33 self.__dict__["____dict"][name] = value
\r
35 return "<AttrFrontend %s>" % (self.__dict__["____dict"].keys(),)
\r
37 # installs an rpyc-enabled exception hook. this happens automatically when the module
\r
38 # is imported. also, make sure the current excepthook is the original one, so we dont
\r
39 # install our hook twice (and thus cause infinite recursion) in case the module is reloaded
\r
40 def rpyc_excepthook(exctype, value, traceback):
\r
41 if hasattr(value, "_remote_traceback"):
\r
42 print >> sys.stderr, "======= Remote traceback ======="
\r
43 print >> sys.stderr, value._remote_traceback
\r
44 print >> sys.stderr, "======= Local exception ======="
\r
45 orig_excepthook(exctype, value, traceback)
\r
47 orig_excepthook(exctype, value, traceback)
\r
49 if sys.excepthook.__name__ != "rpyc_excepthook":
\r
50 orig_excepthook = sys.excepthook
\r
51 sys.excepthook = rpyc_excepthook
\r