[Zodb-checkins] CVS: StandaloneZODB/ZEO - asyncwrap.py:1.1.2.1 StorageServer.py:1.28.2.3 zrpc.py:1.18.2.2

Jeremy Hylton jeremy@zope.com
Wed, 22 Aug 2001 17:04:41 -0400


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

Modified Files:
      Tag: zeo-1_0-branch
	StorageServer.py zrpc.py 
Added Files:
      Tag: zeo-1_0-branch
	asyncwrap.py 
Log Message:
Use asyncwrap to call asyncore.loop() and asyncore.poll()


=== Added File StandaloneZODB/ZEO/asyncwrap.py ===
"""A wrapper for asyncore that provides robust exception handling.

The poll() and loop() calls exported by asyncore can raise exceptions.
asyncore uses either the select() or poll() system call.  It is
possible for those system calls to fail, returning, for example,
EINTR.  Python raises a select.error when an error occurs.  If the
program using asyncore doesn't catch the exception, it will die with
an uncaught exception.

This module exports safer versions of loop() and poll() that wrap the
asyncore calls in try/except handlers that catch the errors and do the
right thing.  In most cases, it is safe to catch the error and simply
retry the call.

XXX Operations on asyncore sockets can also fail with exceptions that
can safely be caught and ignored by user programs.  It's not clear if
it would be useful to extend this module with wrappers for those
errors.
"""

# XXX The current implementation requires Python 2.0.  Not sure if
# that's acceptable, depends on how many users want to combine ZEO 1.0
# and Zope 2.3.

import asyncore
import errno
import select

def loop(*args, **kwargs):
    while 1:
        try:
            apply(asyncore.loop, args, kwargs)
        except select.error, err:
            if err[0] != errno.EINTR:
                raise
        else:
            break
    
def poll(*args, **kwargs):
    try:
        apply(asyncore.poll, args, kwargs)
    except select.error, err:
        if err[0] != errno.EINTR:
            raise


=== StandaloneZODB/ZEO/StorageServer.py 1.28.2.2 => 1.28.2.3 ===
 from cStringIO import StringIO
 from ZEO import trigger
+from ZEO import asyncwrap
 
 class StorageServerError(POSException.StorageError): pass
 
@@ -184,8 +185,8 @@
             sock, addr = self.accept()
         except socket.error:
             sys.stderr.write('warning: accept failed\n')
-
-        ZEOConnection(self, sock, addr)
+        else:
+            ZEOConnection(self, sock, addr)
 
     def log_info(self, message, type='info'):
         if type=='error': type=ERROR
@@ -577,7 +578,10 @@
     import ZODB.FileStorage
     name, port = sys.argv[1:3]
     blather(name, port)
-    try: port='',string.atoi(port)
-    except: pass
+    try:
+        port='', int(port)
+    except:
+        pass
+    
     StorageServer(port, ZODB.FileStorage.FileStorage(name))
-    asyncore.loop()
+    asyncwrap.loop()


=== StandaloneZODB/ZEO/zrpc.py 1.18.2.1 => 1.18.2.2 ===
 from smac import SizedMessageAsyncConnection
 import socket, string, struct, asyncore, sys, time, select
-TupleType=type(())
 from zLOG import LOG, TRACE, DEBUG, INFO
+from ZEO import asyncwrap
 
 from errno import EINTR
+TupleType=type(())
 
 # We create a special fast pickler! This allows us
 # to create slightly more efficient pickles and
@@ -186,13 +187,13 @@
             try: r, w, e = select.select([self._fileno],[],[],0.0)
             except select.error, v:
                 if v[0] != EINTR: raise
-            if r: asyncore.poll(0.0, self)
+            if r: asyncwrap.poll(0.0, self)
             else: break
 
     def readLoop(self):
         la=self.__la
         while not la(0):
-            asyncore.poll(60.0, self)
+            asyncwrap.poll(60.0, self)
         self.__lr()
 
     def setLoop(self, map=None, Wakeup=lambda : None):
@@ -242,7 +243,7 @@
         self.message_output(dump(args,1))
         if self.__haveMainLoop:
             self.__Wakeup() # Wake up the main loop
-        else: asyncore.poll(0.0, self)
+        else: asyncwrap.poll(0.0, self)
 
     def setOutOfBand(self, f):
         """Define a call-back function for handling out-of-band communication