setup.py 1.0 KB

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