diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-06-05 20:51:25 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-06-05 20:51:25 +0300 |
| commit | a00b5db4ccc11a4602c50ce66c180a7a46eddde5 (patch) | |
| tree | 53cf214179b1f5bf6f7c42d070b7f323702bbc92 | |
| parent | a922035367b64429facb16ac824a2bbaf3839116 (diff) | |
Fix app init with wsgi
| -rw-r--r-- | app.py | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -15,9 +15,6 @@ from dataclasses import dataclass from flask import Flask, render_template, redirect, request, make_response from flask_compress import Compress -app = Flask(__name__) -Compress(app) - import db import email_client @@ -37,6 +34,26 @@ VOTER_NAME_MAX_LENGTH = 100 Task = Callable[[], None] background_tasks_queue: queue.Queue[Task] = queue.Queue() +### Init + +def background_thread(): + print("Background thread started") + while True: + task = background_tasks_queue.get() + task() + time.sleep(0.1) + +def create_app() -> Flask: + print("Running create app!") + threading.Thread(target=background_thread, daemon=True).start() + app = Flask(__name__) + Compress(app) + return app + +app = create_app() + +### Routes + def voter_selection_on_choice(voter_name: str, choice: db.Choice) -> int | None: for vote in choice.votes: if vote.voter_name == voter_name: @@ -409,14 +426,3 @@ def toggle_display_mode(): resp.set_cookie("diddle_display_mode", display_mode, samesite="Lax", secure=False) return resp - -### Background thread - -def background_thread(): - print("Background thread started") - while True: - task = background_tasks_queue.get() - task() - time.sleep(0.1) - -threading.Thread(target=background_thread, daemon=True).start() |
