[Idle-dev] CVS: idle rpc.py,1.12,1.13

Kurt B. Kaiser kbk@users.sourceforge.net
Fri, 24 Jan 2003 19:26:37 -0800


Update of /cvsroot/idlefork/idle
In directory sc8-pr-cvs1:/tmp/cvs-serv12918

Modified Files:
	rpc.py 
Log Message:
1. Eliminate putrequest(): only used in asynccall(), merge it there.
2. Add additional debugging statements and enhance others.
3. Clarify comments.
4. Move SocketIO.nextseq class attribute to beginning of class.


Index: rpc.py
===================================================================
RCS file: /cvsroot/idlefork/idle/rpc.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** rpc.py	31 Dec 2002 16:03:23 -0000	1.12
--- rpc.py	25 Jan 2003 03:26:35 -0000	1.13
***************
*** 91,94 ****
--- 91,96 ----
  class SocketIO:
  
+     nextseq = 0
+ 
      def __init__(self, sock, objtable=None, debugging=None):
          self.mainthread = threading.currentThread()
***************
*** 175,179 ****
  
      def remotecall(self, oid, methodname, args, kwargs):
!         self.debug("remotecall:")
          seq = self.asynccall(oid, methodname, args, kwargs)
          return self.asyncreturn(seq)
--- 177,181 ----
  
      def remotecall(self, oid, methodname, args, kwargs):
!         self.debug("calling asynccall via remotecall")
          seq = self.asynccall(oid, methodname, args, kwargs)
          return self.asyncreturn(seq)
***************
*** 181,191 ****
      def asynccall(self, oid, methodname, args, kwargs):
          request = ("call", (oid, methodname, args, kwargs))
!         seq = self.putrequest(request)
!         self.debug(("asyncall:%d:" % seq), oid, methodname, args, kwargs)
          return seq
  
      def asyncreturn(self, seq):
          response = self.getresponse(seq)
!         self.debug(("asyncreturn:%d:" % seq), response)
          return self.decoderesponse(response)
  
--- 183,195 ----
      def asynccall(self, oid, methodname, args, kwargs):
          request = ("call", (oid, methodname, args, kwargs))
!         seq = self.newseq()
!         self.debug(("asynccall:%d:" % seq), oid, methodname, args, kwargs)
!         self.putmessage((seq, request))
          return seq
  
      def asyncreturn(self, seq):
+         self.debug("asyncreturn:%d:call getresponse(): " % seq)
          response = self.getresponse(seq)
!         self.debug(("asyncreturn:%d:response: " % seq), response)
          return self.decoderesponse(response)
  
***************
*** 195,199 ****
              return what
          if how == "EXCEPTION":
!             self.debug("decoderesponse: Internal EXCEPTION:", what)
              mod, name, args, tb = what
              self.traceback = tb
--- 199,203 ----
              return what
          if how == "EXCEPTION":
!             self.debug("decoderesponse: EXCEPTION:", what)
              mod, name, args, tb = what
              self.traceback = tb
***************
*** 221,224 ****
--- 225,234 ----
  
      def mainloop(self):
+         """Listen on socket until I/O not ready or EOF
+ 
+         pollpacket() will loop looking for seq number None, which never
+         comes.  The loop will exit when self.ioready() returns 0.
+ 
+         """
          try:
              self.getresponse(None)
***************
*** 243,248 ****
  
      def _getresponse(self, myseq):
          if threading.currentThread() is self.mainthread:
!             # Main thread: does all reading of requests and responses
              while 1:
                  response = self.pollresponse(myseq, None)
--- 253,260 ----
  
      def _getresponse(self, myseq):
+         self.debug("_getresponse:myseq:", myseq)
          if threading.currentThread() is self.mainthread:
!             # Main thread: does all reading of requests or responses
!             # Loop here until there is message traffic on the socket
              while 1:
                  response = self.pollresponse(myseq, None)
***************
*** 260,271 ****
              del self.cvars[myseq]
              self.statelock.release()
!             return response
! 
!     def putrequest(self, request):
!         seq = self.newseq()
!         self.putmessage((seq, request))
!         return seq
! 
!     nextseq = 0
  
      def newseq(self):
--- 272,276 ----
              del self.cvars[myseq]
              self.statelock.release()
!             return response  # might be None
  
      def newseq(self):
***************
*** 274,278 ****
  
      def putmessage(self, message):
!         ##self.debug("putmessage: ", message)
          try:
              s = pickle.dumps(message)
--- 279,283 ----
  
      def putmessage(self, message):
!         self.debug("putmessage:%d:" % message[0])
          try:
              s = pickle.dumps(message)
***************
*** 338,351 ****
  
      def pollresponse(self, myseq, wait=0.0):
!         # Loop while there's no more buffered input or until specific response
          while 1:
              message = self.pollmessage(wait)
!             if message is None:
                  return None
              wait = 0.0
              seq, resq = message
              if resq[0] == "call":
!                 self.debug("call_localcall:%d:" % seq)
                  response = self.localcall(resq)
                  self.putmessage((seq, response))
                  continue
--- 343,368 ----
  
      def pollresponse(self, myseq, wait=0.0):
!         """Handle messages received on the socket.
! 
!         Some messages received may be asynchronous 'call' commands, and
!         some may be responses intended for other threads.
! 
!         Loop until message with myseq sequence number is received.  Save others
!         in self.responses and notify the owning thread, except that 'call'
!         commands are handed off to localcall() and the response sent back
!         across the link with the appropriate sequence number.
! 
!         """
          while 1:
              message = self.pollmessage(wait)
!             if message is None:  # socket not ready
                  return None
              wait = 0.0
              seq, resq = message
+             self.debug("pollresponse:%d:myseq:%s" % (seq, myseq))
              if resq[0] == "call":
!                 self.debug("pollresponse:%d:call_localcall" % seq)
                  response = self.localcall(resq)
+                 self.debug("pollresponse:%d:response:%s" % (seq, response))
                  self.putmessage((seq, response))
                  continue
***************
*** 411,415 ****
          working_sock, address = self.listening_sock.accept()
          if self.debugging:
!             print>>sys.__stderr__, "** Connection request from ", address
          if address[0] == '127.0.0.1':
              SocketIO.__init__(self, working_sock)
--- 428,432 ----
          working_sock, address = self.listening_sock.accept()
          if self.debugging:
!             print>>sys.__stderr__, "****** Connection request from ", address
          if address[0] == '127.0.0.1':
              SocketIO.__init__(self, working_sock)