From a021840b59e973528e9031ff2f2835115221a434 Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Wed, 27 Mar 2024 19:56:17 -0500 Subject: [PATCH] moving website_dir to client side session cookie maybe this will allow multiple gunicorn workers? --- app.py | 13 ++++++------- gunicorn_config.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index fa520b3..8c53203 100644 --- a/app.py +++ b/app.py @@ -17,10 +17,9 @@ WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.' website_dir = None def current_website_dir(): if session['requests'] % 5 == 0: - global website_dir - website_dir = str(ROOT_DIR+"/Marvel") + session['website_dir'] = str(ROOT_DIR+"/Marvel") elif session['requests'] % 6 == 0: - website_dir = str(ROOT_DIR+"/Escape") + session['website_dir'] = str(ROOT_DIR+"/Escape") session.pop('requests', None) else: global WEBSITE_DIRS @@ -29,12 +28,12 @@ def current_website_dir(): WEBSITE_DIRS.remove(os.path.isdir(os.path.join(ROOT_DIR, 'Marvel'))) except (ValueError, IndexError) as e: pass - website_dir = random.choice(WEBSITE_DIRS) + session['website_dir'] = random.choice(WEBSITE_DIRS) # Make static files available @app.route('/', methods=['GET']) def static_proxy(filename): - return send_from_directory(website_dir, filename) + return send_from_directory(session['website_dir'], filename) # Serve site index.html @app.route('/', methods=['GET']) @@ -44,7 +43,7 @@ def index(): else: session['requests'] = 1 current_website_dir() - return send_from_directory(website_dir, 'index.html') + return send_from_directory(session['website_dir'], 'index.html') if __name__ == "__main__": - app.run() + app.run(debug=True) diff --git a/gunicorn_config.py b/gunicorn_config.py index 70642dd..0a63ff8 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,2 +1,2 @@ bind = "0.0.0.0:8080" -workers = 1 +workers = 2