[Zodb-checkins] CVS: ZODB4/ZEO/zrpc - connection.py:1.4.2.1 client.py:1.4.2.1

Jeremy Hylton jeremy@zope.com
Tue, 17 Sep 2002 16:17:12 -0400


Update of /cvs-repository/ZODB4/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv9833/zrpc

Modified Files:
      Tag: ZODB4-ZEO-branch
	connection.py client.py 
Log Message:
Zope3 doesn't use asyncore, so I can kill the ThreadedAsync nonsense.



=== ZODB4/ZEO/zrpc/connection.py 1.4 => 1.4.2.1 ===
--- ZODB4/ZEO/zrpc/connection.py:1.4	Fri Jul 26 16:54:47 2002
+++ ZODB4/ZEO/zrpc/connection.py	Tue Sep 17 16:16:42 2002
@@ -16,7 +16,6 @@
 import threading
 import types
 
-import ThreadedAsync
 from ZEO import smac # XXX put smac in zrpc?
 from ZEO.zrpc.error import ZRPCError, DisconnectedError, DecodingError
 from ZEO.zrpc.log import log, short_repr
@@ -75,15 +74,6 @@
         self.closed = 0
         self.msgid = 0
         self.__super_init(sock, addr)
-        # A Connection either uses asyncore directly or relies on an
-        # asyncore mainloop running in a separate thread.  If
-        # thr_async is true, then the mainloop is running in a
-        # separate thread.  If thr_async is true, then the asyncore
-        # trigger (self.trigger) is used to notify that thread of
-        # activity on the current thread.
-        self.thr_async = 0
-        self.trigger = None
-        self._prepare_async()
         self._map = {self._fileno: self}
         self.__call_lock = threading.Lock()
         # The reply lock is used to block when a synchronous call is
@@ -277,38 +267,17 @@
 
     # handle IO, possibly in async mode
 
-    def _prepare_async(self):
-        self.thr_async = 0
-        ThreadedAsync.register_loop_callback(self.set_async)
-        # XXX If we are not in async mode, this will cause dead
-        # Connections to be leaked.
-
-    def set_async(self, map):
-        self.trigger = trigger()
-        self.thr_async = 1
-
-    def is_async(self):
-        if self.thr_async:
-            return 1
-        else:
-            return 0
-
     def _do_async_loop(self):
         "Invoke asyncore mainloop and wait for reply."
         if __debug__:
             log("_do_async_loop() async=%d" % self.is_async(),
                 level=zLOG.DEBUG)
-        if self.is_async():
-            self.trigger.pull_trigger()
-            self.__reply_lock.acquire()
-            # wait until reply...
-        else:
-            # Do loop only if lock is already acquired.  XXX But can't
-            # we already guarantee that the lock is already acquired?
-            while not self.__reply_lock.acquire(0):
-                asyncore.poll(10.0, self._map)
-                if self.closed:
-                    raise DisconnectedError()
+        # Do loop only if lock is already acquired.  XXX But can't
+        # we already guarantee that the lock is already acquired?
+        while not self.__reply_lock.acquire(0):
+            asyncore.poll(10.0, self._map)
+            if self.closed:
+                raise DisconnectedError()
         self.__reply_lock.release()
 
     def _do_async_poll(self, wait_for_reply=0):
@@ -317,10 +286,7 @@
         if __debug__:
             log("_do_async_poll(), async=%d" % self.is_async(),
                 level=zLOG.DEBUG)
-        if self.is_async():
-            self.trigger.pull_trigger()
-        else:
-            asyncore.poll(0.0, self._map)
+        asyncore.poll(0.0, self._map)
 
 class ServerConnection(Connection):
     """Connection on the server side"""
@@ -354,32 +320,10 @@
     def __init__(self, sock, addr, obj, mgr):
         self.__mgr = mgr
         self.__super_init(sock, addr, obj)
-        self.check_mgr_async()
 
     def close_trigger(self):
         # the manager should actually close the trigger
         del self.trigger
-
-    def set_async(self, map):
-        pass
-
-    def _prepare_async(self):
-        # Don't do the register_loop_callback that the superclass does
-        pass
-
-    def check_mgr_async(self):
-        if not self.thr_async and self.__mgr.thr_async:
-            assert self.__mgr.trigger is not None, \
-                   "manager (%s) has no trigger" % self.__mgr
-            self.thr_async = 1
-            self.trigger = self.__mgr.trigger
-            return 1
-        return 0
-
-    def is_async(self):
-        if self.thr_async:
-            return 1
-        return self.check_mgr_async()
 
     def close(self):
         self.__super_close()


=== ZODB4/ZEO/zrpc/client.py 1.4 => 1.4.2.1 ===
--- ZODB4/ZEO/zrpc/client.py:1.4	Fri Jul 26 16:49:39 2002
+++ ZODB4/ZEO/zrpc/client.py	Tue Sep 17 16:16:42 2002
@@ -19,7 +19,6 @@
 import time
 import types
 
-import ThreadedAsync
 import zLOG
 
 from ZEO.zrpc.log import log
@@ -41,9 +40,6 @@
         # attempting to connect.  _thread is protected by _connect_lock.
         self._thread = None
         self._connect_lock = threading.Lock()
-        self.trigger = None
-        self.thr_async = 0
-        ThreadedAsync.register_loop_callback(self.set_async)
 
     def __repr__(self):
         return "<%s for %s>" % (self.__class__.__name__, self.addr)
@@ -94,23 +90,6 @@
             self.connection.close()
         if self.trigger is not None:
             self.trigger.close()
-
-    def set_async(self, map):
-        # This is the callback registered with ThreadedAsync.  The
-        # callback might be called multiple times, so it shouldn't
-        # create a trigger every time and should never do anything
-        # after it's closed.
-
-        # It may be that the only case where it is called multiple
-        # times is in the test suite, where ThreadedAsync's loop can
-        # be started in a child process after a fork.  Regardless,
-        # it's good to be defensive.
-
-        # XXX need each connection started with async==0 to have a
-        # callback
-        if not self.closed and self.trigger is None:
-            self.trigger = trigger()
-            self.thr_async = 1 # XXX needs to be set on the Connection
 
     def attempt_connect(self):
         """Attempt a connection to the server without blocking too long.