Changeset: 4fac2c643232 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4fac2c643232
Modified Files:
        testing/Mtest.py.in
Branch: Feb2013
Log Message:

Start children of Mtest in a separate process group to ease killing them.
This was actually the only reason we still had subprocess26, but I
totally forgot about that since it wasn't documented...


diffs (102 lines):

diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -137,6 +137,44 @@ except ImportError:
             p += os.pathsep + os.environ['PYTHONPATH']
         os.environ['PYTHONPATH'] = p
 
+# Replace os.fork by a version that forks but also sets the process
+# group in the child.  This is done so that we can easily kill a
+# subprocess and its children in case of a timeout.
+# To use this, set the global variable setpgrp to True before calling
+# subprocess.Popen.  It is reset automatically to False so that
+# subprocess of our child don't get their own process group.
+try:
+    os.setpgrp
+except AttributeError:
+    try:
+        os.setpgid
+    except AttributeError:
+        # no function to set process group, so don't replace
+        pass
+    else:
+        # use os.setpgid to set process group
+        def myfork(osfork = os.fork):
+            global setpgrp
+            _setpgrp = setpgrp
+            setpgrp = False
+            pid = osfork()
+            if pid == 0 and _setpgrp:
+                os.setpgrp()
+            return pid
+        os.fork = myfork
+else:
+    # use os.setpgrp to set process group
+    def myfork(osfork = os.fork):
+        global setpgrp
+        _setpgrp = setpgrp
+        setpgrp = False
+        pid = osfork()
+        if pid == 0 and _setpgrp:
+            os.setpgid(0, 0)
+        return pid
+    os.fork = myfork
+setpgrp = False
+
 ttywidth = 0
 if isatty and os.isatty(sys.stdin.fileno()):
     if os.name != 'nt':
@@ -1459,6 +1497,8 @@ def GetBitsAndOIDsAndModsAndStaticAndThr
     cmd.append('--dbpath=%s' % os.path.join(env['GDK_DBFARM'], TSTPREF))
     if procdebug:
         print 'GetBitsAndOIDsAndModsAndStaticAndThreads: starting process "%s" 
(inpipe, outpipe, errpipe)\n' % '" "'.join(cmd)
+    global setpgrp
+    setpgrp = True
     proc = process.Popen(cmd, stdin = process.PIPE, stdout = process.PIPE,
                          stderr = process.PIPE, universal_newlines = True)
     proc.killed = False
@@ -2159,6 +2199,8 @@ def RunTest(env, TST, BusyPorts, COND, o
                         '%s.out.diff.html' % TST])
             if procdebug:
                 print 'RunTest: starting process "%s"\n' % '" "'.join(cmd)
+            global setpgrp
+            setpgrp = True
             proc = process.Popen(cmd, stdout = process.PIPE,
                                  stderr = process.PIPE)
             proc.killed = False
@@ -2229,6 +2271,8 @@ def RunTest(env, TST, BusyPorts, COND, o
                         '%s.err.diff.html' % TST])
             if procdebug:
                 print 'RunTest: starting process "%s"\n' % '" "'.join(cmd)
+            global setpgrp
+            setpgrp = True
             proc = process.Popen(cmd, stdout = process.PIPE,
                                  stderr = process.PIPE)
             proc.killed = False
@@ -2500,6 +2544,8 @@ def LaunchIt(cmd, TestInput, TestOut, Te
 
     if procdebug:
         print 'LaunchIt: starting process "%s" (inpipe)\n' % '" "'.join(cmd)
+    global setpgrp
+    setpgrp = True
     proc = process.Popen(cmd, stdin = process.PIPE, stdout = SrvrOut,
                          stderr = TestErr, universal_newlines = True)
     # maybe buffer output as it comes to avoid deadlock
@@ -2542,6 +2588,8 @@ def RunIt(cmd, TestIn, TestOut, TestErr,
     TestErr.flush()
     if procdebug:
         print 'RunIt: starting process "%s"\n' % '" "'.join(cmd)
+    global setpgrp
+    setpgrp = True
     proc = process.Popen(cmd, stdin = TestIn, stdout = TestOut, stderr = 
TestErr, universal_newlines = True)
     proc.killed = False
     t = Timer(TimeOut, killProc, args = [proc, TestErr, cmd])
@@ -2919,6 +2967,8 @@ def DoIt(env, SERVER, CALL, TST, EXT, PR
 def Check(command, input) :
     if procdebug:
         print 'Check: starting process "%s" (inpipe,outpipe,errpipe)\n' % '" 
"'.join(command)
+    global setpgrp
+    setpgrp = True
     proc = process.Popen(command, stdin = process.PIPE, stdout = process.PIPE,
                          stderr = process.PIPE, universal_newlines = True)
     proc.killed = False
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to