@@ -90,8 +90,6 @@ def get_request(self):
9090
9191class SocketIO :
9292
93- debugging = False
94-
9593 def __init__ (self , sock , objtable = None , debugging = None ):
9694 self .mainthread = threading .currentThread ()
9795 if debugging is not None :
@@ -113,11 +111,10 @@ def close(self):
113111 def debug (self , * args ):
114112 if not self .debugging :
115113 return
116- s = str (threading .currentThread ().getName ())
114+ s = self . location + " " + str (threading .currentThread ().getName ())
117115 for a in args :
118116 s = s + " " + str (a )
119- s = s + "\n "
120- sys .__stderr__ .write (s )
117+ print >> sys .__stderr__ , s
121118
122119 def register (self , oid , object ):
123120 self .objtable [oid ] = object
@@ -159,44 +156,45 @@ def localcall(self, request):
159156 typ , val , tb = info = sys .exc_info ()
160157 sys .last_type , sys .last_value , sys .last_traceback = info
161158 if isinstance (typ , type (Exception )):
162- # Class exceptions
159+ # Class exception
163160 mod = typ .__module__
164161 name = typ .__name__
165162 if issubclass (typ , Exception ):
166163 args = val .args
167164 else :
168165 args = (str (val ),)
169166 else :
170- # String exceptions
167+ # User string exception
171168 mod = None
172169 name = typ
173- args = (str (val ),)
170+ if val is None : val = ''
171+ args = str (val )
174172 tb = traceback .extract_tb (tb )
173+ self .debug ("localcall:EXCEPTION: " , mod , name , args , tb )
175174 return ("EXCEPTION" , (mod , name , args , tb ))
176175
177176 def remotecall (self , oid , methodname , args , kwargs ):
178- self .debug ("remotecall:" , oid , methodname , args , kwargs )
177+ self .debug ("remotecall:" )
179178 seq = self .asynccall (oid , methodname , args , kwargs )
180- ret = self .asyncreturn (seq )
181- self .debug ("return:" , ret )
182- return ret
179+ return self .asyncreturn (seq )
183180
184181 def asynccall (self , oid , methodname , args , kwargs ):
185- self .debug ("asyncall:" , oid , methodname , args , kwargs )
186182 request = ("call" , (oid , methodname , args , kwargs ))
187183 seq = self .putrequest (request )
184+ self .debug (("asyncall:%d:" % seq ), oid , methodname , args , kwargs )
188185 return seq
189186
190187 def asyncreturn (self , seq ):
191188 response = self .getresponse (seq )
192- self .debug ("asyncreturn:" , response )
189+ self .debug (( "asyncreturn:%d:" % seq ) , response )
193190 return self .decoderesponse (response )
194191
195192 def decoderesponse (self , response ):
196193 how , what = response
197194 if how == "OK" :
198195 return what
199196 if how == "EXCEPTION" :
197+ self .debug ("decoderesponse: Internal EXCEPTION:" , what )
200198 mod , name , args , tb = what
201199 self .traceback = tb
202200 if mod : # not string exception
@@ -217,6 +215,7 @@ def decoderesponse(self, response):
217215 # do the best we can:
218216 raise name , args
219217 if how == "ERROR" :
218+ self .debug ("decoderesponse: Internal ERROR:" , what )
220219 raise RuntimeError , what
221220 raise SystemError , (how , what )
222221
@@ -274,6 +273,7 @@ def newseq(self):
274273 return seq
275274
276275 def putmessage (self , message ):
276+ ##self.debug("putmessage: ", message)
277277 try :
278278 s = pickle .dumps (message )
279279 except :
@@ -345,6 +345,7 @@ def pollresponse(self, myseq, wait=0.0):
345345 wait = 0.0
346346 seq , resq = message
347347 if resq [0 ] == "call" :
348+ self .debug ("call_localcall:%d:" % seq )
348349 response = self .localcall (resq )
349350 self .putmessage ((seq , response ))
350351 continue
@@ -377,7 +378,8 @@ def __init__(self, oid):
377378
378379class RPCHandler (SocketServer .BaseRequestHandler , SocketIO ):
379380
380- debugging = 0
381+ debugging = False
382+ location = "#S" # Server
381383
382384 def __init__ (self , sock , addr , svr ):
383385 svr .current_handler = self ## cgt xxx
@@ -393,6 +395,9 @@ def get_remote_proxy(self, oid):
393395
394396class RPCClient (SocketIO ):
395397
398+ debugging = False
399+ location = "#C" # Client
400+
396401 nextseq = 1 # Requests coming from the client are odd numbered
397402
398403 def __init__ (self , address , family = socket .AF_INET , type = socket .SOCK_STREAM ):
0 commit comments