From c735b1e496b74173399f4ca002546c8cff2fbe7a Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 24 Jun 2023 16:05:50 +0200 Subject: [PATCH] Automatically close db connexion --- partitioncloud/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/partitioncloud/__init__.py b/partitioncloud/__init__.py index a76e837..f3512bd 100644 --- a/partitioncloud/__init__.py +++ b/partitioncloud/__init__.py @@ -82,5 +82,13 @@ def add_user(): return render_template("auth/register.html", albums=get_all_albums(), user=current_user) +# Automatically close db after each request +@app.after_request +def after_request(response): + if ('db' in g) and (g.db is not None): + g.db.close() + return response + + if __name__ == "__main__": app.run(host="0.0.0.0")