[Buildbot-commits] buildbot/buildbot/scripts runner.py,1.18,1.19

Brian Warner warner at users.sourceforge.net
Fri May 6 05:01:13 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25130/buildbot/scripts

Modified Files:
	runner.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-141
Creator:  Brian Warner <warner at monolith.lothar.com>

Merged from warner at monolith.lothar.com--2005 (patch 6)

Patches applied:

 * warner at monolith.lothar.com--2005/buildbot--dev--0--patch-6
   don't spawn twistd or /bin/kill in 'buildbot start/stop'


Index: runner.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/scripts/runner.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- runner.py	6 May 2005 04:57:58 -0000	1.18
+++ runner.py	6 May 2005 05:01:11 -0000	1.19
@@ -2,7 +2,7 @@
 
 # N.B.: don't import anything that might pull in a reactor yet. Some of our
 # subcommands want to load modules that need the gtk reactor.
-import os, os.path, sys, shutil, stat, re
+import os, os.path, sys, shutil, stat, re, time
 from twisted.python import usage, util, runtime
 
 # this is mostly just a front-end for mktap, twistd, and kill(1), but in the
@@ -261,23 +261,47 @@
         # yes, this is clunky. Preferring the Makefile lets slave admins do
         # useful things like set up environment variables for the buildslave.
         cmd = "make start"
+        if not quiet: print cmd
+        os.system(cmd)
     else:
-        reactor_arg = ""
-        if sys.platform == "win32":
-            reactor_arg = "--reactor=win32"
-        cmd = "twistd %s --no_save -f buildbot.tap" % reactor_arg
-    if not quiet: print cmd
-    os.system(cmd)
+        # see if we can launch the application without actually having to
+        # spawn twistd, since spawning processes correctly is a real hassle
+        # on windows.
+        from twisted.python.runtime import platformType
+        argv = ["twistd", "--no_save", "--python=buildbot.tac"]
+        if platformType == "win32":
+            argv.append("--reactor=win32")
+        sys.argv = argv
+
+        # this is copied from bin/twistd
+        if platformType == "win32":
+            from twisted.scripts._twistw import run
+        else:
+            from twisted.scripts.twistd import run
+        run()
+
     sys.exit(0)
 
-def stop(config, signal=""):
+def stop(config, signame="TERM"):
+    import signal
     basedir = config['basedir']
     quiet = config['quiet']
     os.chdir(basedir)
-    cmd = "kill %s `cat twistd.pid`" % signal
-    if not quiet: print cmd
-    os.system(cmd)
-    # TODO: poll once per second until twistd.pid goes away
+    f = open("twistd.pid", "rt")
+    pid = int(f.read().strip())
+    signum = getattr(signal, "SIG"+signame)
+    timer = 0
+    os.kill(pid, signum)
+    while timer < 5:
+        # poll once per second until twistd.pid goes away, up to 5 seconds
+        try:
+            os.kill(pid, signum)
+        except OSError:
+            print "buildbot process %d is dead" % pid
+            sys.exit(0)
+        timer += 1
+        time.sleep(1)
+    print "never saw process go away"
     sys.exit(0)
 
 def loadOptions(filename="options", here=None, home=None):





More information about the Commits mailing list