Browse Source

Flask: Update setup files.

INADA Naoki 12 years ago
parent
commit
eab53a36d0
4 changed files with 47 additions and 44 deletions
  1. 0 14
      flask/run_pypy.py
  2. 11 13
      flask/setup.py
  3. 22 0
      flask/setup_py3.py
  4. 14 17
      flask/setup_pypy.py

+ 0 - 14
flask/run_pypy.py

@@ -1,14 +0,0 @@
-import tornado.options
-import tornado.wsgi
-import tornado.httpserver
-from tornado.options import options
-
-tornado.options.define('port', default=8080, type=int, help=("Server port"))
-tornado.options.parse_command_line()
-
-import app
-container = tornado.wsgi.WSGIContainer(app.app)
-server = tornado.httpserver.HTTPServer(container)
-server.bind(options.port)
-server.start(8)
-tornado.ioloop.IOLoop.instance().start()

+ 11 - 13
flask/setup.py

@@ -1,22 +1,20 @@
 import subprocess
-import sys
 import setup_util
-import os
+
+proc = None
+
 
 def start(args):
     setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
-    subprocess.Popen("gunicorn app:app -k meinheld.gmeinheld.MeinheldWorker -b 0.0.0.0:8080 -w " +
-                     str((args.max_threads * 2)) + " --preload --log-level=critical", shell=True, cwd="flask")
+    proc = subprocess.Popen(
+        "gunicorn app:app -k meinheld.gmeinheld.MeinheldWorker -b 0.0.0.0:8080 -w " +
+        str((args.max_threads * 2)) + " --preload --log-level=critical", shell=True, cwd="flask")
     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
+    if proc is None:
+        return 0
+    proc.terminate()
+    proc = None
     return 0

+ 22 - 0
flask/setup_py3.py

@@ -0,0 +1,22 @@
+import subprocess
+import setup_util
+
+proc = None
+
+
+def start(args):
+    global proc
+    setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
+    proc = subprocess.Popen(
+        "~/FrameworkBenchmarks/installs/python-3.3.2/bin/gunicorn " +
+        "app:app -k meinheld.gmeinheld.MeinheldWorker -b 0.0.0.0:8080 -w " +
+        str((args.max_threads * 2)) + " --preload --log-level=critical", shell=True, cwd="flask")
+    return 0
+
+def stop():
+    global proc
+    if proc is None:
+        return 0
+    proc.terminate()
+    proc = None
+    return 0

+ 14 - 17
flask/setup_pypy.py

@@ -1,25 +1,22 @@
 import subprocess
-import sys
 import setup_util
-import os
 
 proc = None
 
+
 def start(args):
-  global proc
-  setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
-  proc = subprocess.Popen("~/FrameworkBenchmarks/installs/pypy-2.0.2/bin/pypy run_pypy.py --port=8080 --logging=error",
-                          shell=True, cwd="flask")
-  return 0
+    global proc
+    setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
+    proc = subprocess.Popen(
+        "~/FrameworkBenchmarks/installs/pypy-2.0.2/bin/gunicorn " +
+        "app:app -k tornado -b 0.0.0.0:8080 -w " +
+        str((args.max_threads * 2)) + " --preload --log-level=critical", shell=True, cwd="flask")
+    return 0
 
 def stop():
-  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
-  out, err = p.communicate()
-  for line in out.splitlines():
-    if 'pypy' in line and 'run-tests' not in line:
-      try:
-        pid = int(line.split(None, 2)[1])
-        os.kill(pid, 9)
-      except OSError:
-        pass
-  return 0 
+    global proc
+    if proc is None:
+        return 0
+    proc.terminate()
+    proc = None
+    return 0