setup.py 990 B

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 hello.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="wsgi", stderr=errfile, stdout=logfile, shell=True)
  21. with open("wsgi/circus.ini", "w") as f:
  22. f.write(CIRCUS_INI.format(BIN=bin_dir, PROCS=NCPU*2))
  23. proc = subprocess.Popen([bin_dir + "/circusd", "circus.ini"],
  24. cwd="wsgi", stderr=errfile, stdout=logfile)
  25. return 0
  26. def stop(logfile, errfile):
  27. global proc
  28. if proc is None:
  29. return 0
  30. proc.terminate()
  31. proc.wait()
  32. proc = None
  33. return 0