[Zodb-checkins] CVS: StandaloneZODB/ZEO/zrpc - connection.py:1.6

Jeremy Hylton jeremy@zope.com
Tue, 6 Aug 2002 19:10:31 -0400


Update of /cvs-repository/StandaloneZODB/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv32668/ZEO/zrpc

Modified Files:
	connection.py 
Log Message:
Add MTDelay() that blocks reply() on an event until send_reply() is ready.

Add a poll call in send_reply() so that synchronous calls made when
there is no other traffic don't cause long delays.  (This probably
only occurs during the pack tests.)



=== StandaloneZODB/ZEO/zrpc/connection.py 1.5 => 1.6 ===
     def reply(self, obj):
         self.send_reply(self.msgid, obj)
 
+class MTDelay(Delay):
+
+    def __init__(self):
+        self.ready = threading.Event()
+
+    def set_sender(self, msgid, send_reply):
+        Delay.set_sender(self, msgid, send_reply)
+        self.ready.set()
+
+    def reply(self, obj):
+        self.ready.wait()
+        Delay.reply(self, obj)
+
 class Connection(smac.SizedMessageAsyncConnection):
     """Dispatcher for RPC on object on both sides of socket.
 
@@ -206,6 +219,7 @@
     def send_reply(self, msgid, ret):
         msg = self.marshal.encode(msgid, 0, REPLY, ret)
         self.message_output(msg)
+        self._do_async_poll()
 
     def return_error(self, msgid, flags, err_type, err_value):
         if flags is None: