Start gunicorn server and return the process.
(worker_class, workers, threads, connections, bind, extra_args=None)
| 40 | |
| 41 | |
| 42 | def start_gunicorn(worker_class, workers, threads, connections, bind, extra_args=None): |
| 43 | """Start gunicorn server and return the process.""" |
| 44 | cmd = [ |
| 45 | sys.executable, '-m', 'gunicorn', |
| 46 | '--worker-class', worker_class, |
| 47 | '--workers', str(workers), |
| 48 | '--threads', str(threads), |
| 49 | '--worker-connections', str(connections), |
| 50 | '--bind', bind, |
| 51 | '--access-logfile', '-', |
| 52 | '--error-logfile', '-', |
| 53 | '--log-level', 'warning', |
| 54 | APP_MODULE, |
| 55 | ] |
| 56 | if extra_args: |
| 57 | cmd.extend(extra_args) |
| 58 | |
| 59 | env = os.environ.copy() |
| 60 | env['PYTHONPATH'] = str(BENCHMARK_DIR.parent) |
| 61 | |
| 62 | proc = subprocess.Popen( |
| 63 | cmd, |
| 64 | cwd=BENCHMARK_DIR, |
| 65 | env=env, |
| 66 | stdout=subprocess.PIPE, |
| 67 | stderr=subprocess.PIPE, |
| 68 | ) |
| 69 | |
| 70 | # Wait for server to be ready |
| 71 | time.sleep(2) |
| 72 | return proc |
| 73 | |
| 74 | |
| 75 | def stop_gunicorn(proc): |