changeset 90:a020f1b2c456

Be tolerant of EAGAIN when sending messages to parent process.
author Allan Saddi <allan@saddi.com>
date Mon, 04 May 2009 13:33:39 -0700
parents c3f6c5101e4d
children fa0bc062585c beeb0bcf8eb5
files flup/server/preforkserver.py
diffstat 1 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/flup/server/preforkserver.py	Mon Feb 02 23:55:25 2009 -0800
     1.2 +++ b/flup/server/preforkserver.py	Mon May 04 13:33:39 2009 -0700
     1.3 @@ -309,6 +309,21 @@
     1.4          """Override to provide access control."""
     1.5          return True
     1.6  
     1.7 +    def _notifyParent(self, parent, msg):
     1.8 +        """Send message to parent, ignoring EPIPE and retrying on EAGAIN"""
     1.9 +        while True:
    1.10 +            try:
    1.11 +                parent.send(msg)
    1.12 +                return True
    1.13 +            except socket.error, e:
    1.14 +                if e[0] == errno.EPIPE:
    1.15 +                    return False # Parent is gone
    1.16 +                if e[0] == errno.EAGAIN:
    1.17 +                    # Wait for socket change before sending again
    1.18 +                    select.select([], [parent], [])
    1.19 +                else:
    1.20 +                    raise
    1.21 +                
    1.22      def _child(self, sock, parent):
    1.23          """Main loop for children."""
    1.24          requestCount = 0
    1.25 @@ -353,12 +368,7 @@
    1.26                  continue
    1.27  
    1.28              # Notify parent we're no longer available.
    1.29 -            try:
    1.30 -                parent.send('\x00')
    1.31 -            except socket.error, e:
    1.32 -                # If parent is gone, finish up this request.
    1.33 -                if e[0] != errno.EPIPE:
    1.34 -                    raise
    1.35 +            self._notifyParent(parent, '\x00')
    1.36  
    1.37              # Do the job.
    1.38              self._jobClass(clientSock, addr, *self._jobArgs).run()
    1.39 @@ -370,13 +380,8 @@
    1.40                      break
    1.41                  
    1.42              # Tell parent we're free again.
    1.43 -            try:
    1.44 -                parent.send('\xff')
    1.45 -            except socket.error, e:
    1.46 -                if e[0] == errno.EPIPE:
    1.47 -                    # Parent is gone.
    1.48 -                    return
    1.49 -                raise
    1.50 +            if not self._notifyParent(parent, '\xff'):
    1.51 +                return # Parent is gone.
    1.52  
    1.53      # Signal handlers
    1.54