[Zodb-checkins] CVS: ZODB3/zdaemon - zdaemon.py:1.18

Guido van Rossum guido@python.org
Thu, 14 Nov 2002 17:03:46 -0500


Update of /cvs-repository/ZODB3/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv6483

Modified Files:
	zdaemon.py 
Log Message:
Handle some errors differently.  os.waitpid() errors are ignored.
os.fork() errors cause spawn() to return 0; the code that calls it
sets a delay and will try again when the delay is over.


=== ZODB3/zdaemon/zdaemon.py 1.17 => 1.18 ===
--- ZODB3/zdaemon/zdaemon.py:1.17	Wed Nov 13 17:59:37 2002
+++ ZODB3/zdaemon/zdaemon.py	Thu Nov 14 17:03:46 2002
@@ -217,12 +217,14 @@
     def spawn(self):
         """Start the subprocess.  It must not be running already.
 
-        Return the process id.  If the fork() call fails, an exception
-        is raised (and not caught).
+        Return the process id.  If the fork() call fails, return 0.
         """
         assert not self.pid
         self.lasttime = time.time()
-        pid = os.fork()
+        try:
+            pid = os.fork()
+        except os.error:
+            return 0
         if pid != 0:
             # Parent
             self.pid = pid
@@ -386,7 +388,10 @@
     waitstatus = None
 
     def sigchild(self, sig, frame):
-        pid, sts = os.waitpid(-1, os.WNOHANG)
+        try:
+            pid, sts = os.waitpid(-1, os.WNOHANG)
+        except os.error:
+            return
         if pid:
             self.waitstatus = pid, sts
 
@@ -422,7 +427,10 @@
         info("daemon manager started")
         while self.mood >= 0 or self.proc.pid:
             if self.mood > 0 and not self.proc.pid and not self.delay:
-                self.proc.spawn()
+                pid = self.proc.spawn()
+                if not pid:
+                    # Can't fork.  Try again later...
+                    self.delay = time.time() + self.backofflimit
             if self.waitstatus:
                 self.reportstatus()
             r, w, x = [self.mastersocket], [], []