setup_py3.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import subprocess
  2. import setup_util
  3. import multiprocessing
  4. import os
  5. PY2BIN = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
  6. PY3BIN = os.path.expanduser('~/FrameworkBenchmarks/installs/py3/bin')
  7. NCPU = multiprocessing.cpu_count()
  8. CIRCUS_INI = """\
  9. [watcher:app]
  10. cmd = {BIN}/chaussette --fd=$(circus.sockets.app) --backend=meinheld app.app
  11. use_sockets = True
  12. numprocesses = {PROCS}
  13. [socket:app]
  14. host = 0.0.0.0
  15. port = 8080
  16. """
  17. proc = None
  18. def start(args, logfile, errfile):
  19. global proc
  20. subprocess.check_call(PY3BIN + "/pip3 install -r requirements.txt",
  21. cwd="flask", stderr=errfile, stdout=logfile, shell=True)
  22. with open("flask/circus.ini", "w") as f:
  23. f.write(CIRCUS_INI.format(BIN=PY3BIN, PROCS=NCPU*3))
  24. setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
  25. proc = subprocess.Popen([PY2BIN + "/circusd", "circus.ini"],
  26. cwd="flask", stderr=errfile, stdout=logfile)
  27. return 0
  28. def stop(logfile, errfile):
  29. global proc
  30. if proc is None:
  31. return 0
  32. proc.terminate()
  33. proc = None
  34. return 0