Browse Source

django-stripped: Fix setup script.

INADA Naoki 12 years ago
parent
commit
d07347ec10
1 changed files with 25 additions and 17 deletions
  1. 25 17
      django-stripped/setup.py

+ 25 - 17
django-stripped/setup.py

@@ -1,23 +1,31 @@
 import subprocess
-import multiprocessing
-import sys
 import setup_util
+import multiprocessing
 import os
 
+bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
+NCPU = multiprocessing.cpu_count()
+
+proc = None
+
+
 def start(args):
-  setup_util.replace_text("django-stripped/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
-  subprocess.Popen("gunicorn hello.wsgi:application --worker-class=meinheld.gmeinheld.MeinheldWorker -b 0.0.0.0:8080 -w " +
-                   str((multiprocessing.cpu_count() * 3)) + " --log-level=critical", shell=True, cwd="django-stripped/hello")
-  return 0
-def stop():
-  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
-  out, err = p.communicate()
-  for line in out.splitlines():
-    if 'gunicorn' in line:
-      try:
-        pid = int(line.split(None, 2)[1])
-        os.kill(pid, 9)
-      except OSError:
-        pass
+    global proc
+    setup_util.replace_text("django-stripped/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
+    proc = subprocess.Popen([
+        bin_dir + "/gunicorn",
+        "hello.wsgi:application",
+        "-k", "meinheld.gmeinheld.MeinheldWorker",
+        "-b", "0.0.0.0:8080",
+        '-w', str(NCPU*3),
+        "--log-level=critical"],
+        cwd="django-stripped/hello")
+    return 0
 
-  return 0
+def stop():
+    global proc
+    if proc is None:
+        return 0
+    proc.terminate()
+    proc = None
+    return 0