[Twisted-commits] Defer SIGCHLD processing until the next event loop round.

tv CVS twisted-python@twistedmatrix.com
Sat, 15 Mar 2003 06:29:31 -0600


Modified files:
Twisted/twisted/internet/process.py 1.53 1.54
Twisted/twisted/internet/default.py 1.67 1.68

Log message:
Defer SIGCHLD processing until the next event loop round.

Also, it's called SIGCHLD, not SIGCHILD. Be greppable and don't
confuse people.


ViewCVS links:
http://twistedmatrix.com/users/jh.twistd/viewcvs/cgi/viewcvs.cgi/twisted/internet/process.py.diff?r1=text&tr1=1.53&r2=text&tr2=1.54&cvsroot=Twisted
http://twistedmatrix.com/users/jh.twistd/viewcvs/cgi/viewcvs.cgi/twisted/internet/default.py.diff?r1=text&tr1=1.67&r2=text&tr2=1.68&cvsroot=Twisted

Index: Twisted/twisted/internet/process.py
diff -u Twisted/twisted/internet/process.py:1.53 Twisted/twisted/internet/process.py:1.54
--- Twisted/twisted/internet/process.py:1.53	Sat Mar 15 03:58:42 2003
+++ Twisted/twisted/internet/process.py	Sat Mar 15 04:28:30 2003
@@ -61,14 +61,27 @@
 
 reapProcessHandlers = {}
 
-def reapAllProcesses(signum, frame):
+def _reapAllProcesses():
     """Reap all registered processes.
 
-    This gets called on SIGCHILD.
+    This gets after a SIGCHLD, on the next event loop iteration.
     """
     for process in reapProcessHandlers.values():
         process.reapProcess()
 
+def reapAllProcesses(signum, frame, reactor):
+    """Reap all registered processes.
+
+    This gets called on SIGCHLD. We do no processing inside a signal
+    handler, as the calls we make here could occur between any two
+    python bytecode instructions. Deferring processing to the next
+    eventloop round prevents us from violating the state constraints
+    of arbitrary classes. Note that a Reactor must be able to accept
+    callLater calls at any time, even interleaved inside it's own
+    methods; it must block SIGCHLD if it is unable to guarantee this.
+
+    """
+    reactor.callLater(0, _reapAllProcesses)
 
 def registerReapProccessHandler(pid, process):
     if reapProcessHandlers.has_key(pid):

Index: Twisted/twisted/internet/default.py
diff -u Twisted/twisted/internet/default.py:1.67 Twisted/twisted/internet/default.py:1.68
--- Twisted/twisted/internet/default.py:1.67	Wed Mar  5 09:16:21 2003
+++ Twisted/twisted/internet/default.py	Sat Mar 15 04:28:30 2003
@@ -1,5 +1,5 @@
 # -*- Python -*-
-# $Id: default.py,v 1.67 2003/03/05 17:16:21 itamarst Exp $
+# $Id: default.py,v 1.68 2003/03/15 12:28:30 tv Exp $
 #
 # Twisted, the Framework of Your Internet
 # Copyright (C) 2001 Matthew W. Lefkowitz
@@ -93,7 +93,9 @@
             signal.signal(signal.SIGBREAK, self.sigBreak)
 
         if platform.getType() == 'posix':
-            signal.signal(signal.SIGCHLD, process.reapAllProcesses)
+            signal.signal(signal.SIGCHLD,
+                          lambda signum,frame,reactor=self:
+                          process.reapAllProcesses(signum, frame, reactor))
 
     def startRunning(self, installSignalHandlers=1):
         threadable.registerAsIOThread()