diff --git a/forum/panneau.py b/forum/panneau.py index 43ab928..624ad84 100644 --- a/forum/panneau.py +++ b/forum/panneau.py @@ -11,6 +11,7 @@ Second serveur, sur la même base que le forum (python forum/panneau.py --port 8 Variables d'environnement : celles du forum (FORUM_HUB_URL, FORUM_CLIENT_ID, FORUM_OAUTH_SECRET[_FILE], FORUM_PROPRIETAIRE_ID) + FORUM_PANNEAU_REDIRECT_URI (défaut : http://localhost:/connexion/retour). """ +import threading import argparse import hashlib import hmac @@ -316,6 +317,16 @@ class Handler(BaseHTTPRequestHandler): def creer_serveur(forum, port=0, hote="127.0.0.1", reglages=None): h = type("H", (Handler,), {"app": App(forum, reglages or connexion.Reglages())}) + # Une seule connexion SQLite partagée entre les fils : les requêtes passent une par une + # (sinon « bad parameter or other API misuse » et connexion coupée quand plusieurs arrivent ensemble). + VERROU_BASE = threading.RLock() + for nom in ("do_GET", "do_POST", "do_HEAD"): + orig = getattr(h, nom, None) + if orig is not None: + def enveloppe(self, _orig=orig): + with VERROU_BASE: + return _orig(self) + setattr(h, nom, enveloppe) return ThreadingHTTPServer((hote, port), h) diff --git a/forum/server.py b/forum/server.py index da69941..fc7a642 100644 --- a/forum/server.py +++ b/forum/server.py @@ -2049,6 +2049,16 @@ def form_supprimer(action, champ, ident, classe="suppr", resume="Supprimer", aid def creer_serveur(forum, port=0, hote="127.0.0.1", reglages=None): h = type("H", (Handler,), {"app": App(forum, reglages or connexion.Reglages())}) + # Une seule connexion SQLite partagée entre les fils : les requêtes passent une par une + # (sinon « bad parameter or other API misuse » et connexion coupée quand plusieurs arrivent ensemble). + VERROU_BASE = threading.RLock() + for nom in ("do_GET", "do_POST", "do_HEAD"): + orig = getattr(h, nom, None) + if orig is not None: + def enveloppe(self, _orig=orig): + with VERROU_BASE: + return _orig(self) + setattr(h, nom, enveloppe) return ThreadingHTTPServer((hote, port), h)