setup_pg.py 939 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import subprocess
  3. import sys
  4. import time
  5. bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
  6. python = os.path.expanduser(os.path.join(bin_dir, 'python'))
  7. pip = os.path.expanduser(os.path.join(bin_dir, 'pip'))
  8. cwd = os.path.expanduser('~/FrameworkBenchmarks/tornado')
  9. def start(args, logfile, errfile):
  10. subprocess.Popen(
  11. python + ' server.py --port=8080 --postgres=%s --logging=error' % (args.database_host,),
  12. shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
  13. return 0
  14. def stop(logfile, errfile):
  15. for line in subprocess.check_output(['ps', 'aux']).splitlines():
  16. if 'server.py --port=8080' in line:
  17. pid = int(line.split(None, 2)[1])
  18. os.kill(pid, 9)
  19. return 0
  20. if __name__ == '__main__':
  21. class DummyArg:
  22. database_host = 'localhost'
  23. start(DummyArg(), sys.stderr, sys.stderr)
  24. time.sleep(1)
  25. stop(sys.stderr, sys.stderr)