def main(): import meinheld import threading from multiprocessing import Process prepare_static('static/') with app.test_request_context(): initialize() port = int(os.environ.get("PORT", '5000')) def kill_all(): for w in workers: w.terminate() signal.signal(signal.SIGTERM, kill_all) def run(): #meinheld.spawn(subscribe_update) th = threading.Thread(target=subscribe_update) th.daemon = True th.start() meinheld.run(app.wsgi_app) meinheld.set_backlog(128) meinheld.set_keepalive(1) meinheld.listen(('0.0.0.0', port)) meinheld.set_access_logger(None) workers = [] for i in xrange(6): w = Process(target=run) w.start() workers.append(w) while True: for w in workers: w.join(1)
workers = [] def hello_world(environ, start_response): status = '200 OK' res = b"Hello world!" response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(res)))] start_response(status, response_headers) #print(environ) return [res] def run(app, i): meinheld.run(app) def kill_all(sig, st): for w in workers: w.terminate() def start(num=4): for i in range(num): p = Process(name="worker-%d" % i, target=run, args=(hello_world,i)) workers.append(p) p.start() signal.signal(signal.SIGTERM, kill_all) meinheld.set_keepalive(10) meinheld.set_access_logger(None) meinheld.set_error_logger(None) meinheld.listen(("0.0.0.0", 8000)) start()
res = b"Hello world!" response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(res)))] start_response(status, response_headers) #print(environ) return [res] def run(app, i): meinheld.run(app) def kill_all(sig, st): for w in workers: w.terminate() def start(num=4): for i in range(num): p = Process(name="worker-%d" % i, target=run, args=(hello_world, i)) workers.append(p) p.start() signal.signal(signal.SIGTERM, kill_all) meinheld.set_keepalive(10) meinheld.set_access_logger(None) meinheld.set_error_logger(None) meinheld.listen(("0.0.0.0", 8000)) start()
def disable_logs(): meinheld.set_access_logger(None) meinheld.set_error_logger(None) meinheld.server.set_access_logger(None)