[Zope-Checkins] CVS: Zope/ZServer/medusa - asyncore.py:1.17.2.1 http_server.py:1.30.40.1

Chris McDonough chrism@zope.com
Fri, 15 Mar 2002 14:36:33 -0500


Update of /cvs-repository/Zope/ZServer/medusa
In directory cvs.zope.org:/tmp/cvs-serv19763/ZServer/medusa

Modified Files:
      Tag: chrism_logrotate_branch
	asyncore.py http_server.py 
Log Message:
Patched up z2.py and some of asyncore to be able to deal with signals.

In this branch, Zope will:

- open and close all of its logfiles upon receving a USR2 signal

- restart "cleanly" upon receiving a HUP signal

- shutdown "cleanly" upon receiving a TERM or INT signal.



=== Zope/ZServer/medusa/asyncore.py 1.17 => 1.17.2.1 ===
                 self.handle_close()
                 return ''
+            if why[0] == EAGAIN:
+                # Happens as a result of a nonfatal signal when select is
+                # interrupted
+                return ''
             else:
                 raise socket.error, why
 
@@ -524,13 +528,16 @@
             # NOTE: this is a difference from the Python 2.2 library
             # version of asyncore.py. This prevents a hanging condition
             # on Linux 2.2 based systems.
-            while 1:
+            i = 0
+            while i < 5: # this is a guess
                 try:
                     return apply (os.read, (self.fd,)+args)
                 except exceptions.OSError, why:
                     if why[0] != EAGAIN:
                         raise
-
+                    else:
+                        i = i + 1
+                        
         def send (self, *args):
             return apply (os.write, (self.fd,)+args)
 


=== Zope/ZServer/medusa/http_server.py 1.30 => 1.30.40.1 ===
         self.total_clients.increment()
         try:
-            conn, addr = self.accept()
+            tup = self.accept()
         except socket.error:
                 # linux: on rare occasions we get a bogus socket back from
                 # accept.  socketmodule.c:makesockaddr complains that the
                 # address family is unknown.  We don't want the whole server
                 # to shut down because of this.
-            self.log_info ('warning: server accept() threw an exception', 'warning')
+            self.log_info ('warning: server accept() threw an exception',
+                           'warning')
+            self.total_clients.decrement()
             return
+        try:
+            conn, addr = tup
         except TypeError:
-                # unpack non-sequence.  this can happen when a read event
-                # fires on a listening socket, but when we call accept()
-                # we get EWOULDBLOCK, so dispatcher.accept() returns None.
-                # Seen on FreeBSD3.
-            self.log_info ('warning: server accept() threw EWOULDBLOCK', 'warning')
+            # unpack non-sequence.  this can happen when a read event
+            # fires on a listening socket, but when we call accept()
+            # we get EWOULDBLOCK, so dispatcher.accept() returns None.
+            # Seen on FreeBSD3 and Linux.
+            #self.log_info ('warning: server accept() returned %s '
+            #               '(EWOULDBLOCK?)' % tup, 'warning')
+            self.total_clients.decrement()
             return
-            
+
         self.channel_class (self, conn, addr)
         
     def install_handler (self, handler, back=0):