From 5a38f2a853ab1b5909fc8398d88033c332ab1528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 19 May 2026 18:19:59 +0200 Subject: [PATCH] Close database after initialization of Pool from WSGI application The psycopg pool starts worker threads that must be stopped. Closes #14849 (grafted from fb2059f652653820142d67f34fd58953decf48f3) --HG-- branch : 8.0 --- trytond/trytond/application.py | 7 ++++++- trytond/trytond/backend/postgresql/database.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/trytond/trytond/application.py b/trytond/trytond/application.py index bc10f0ebaa..0001fada77 100644 --- a/trytond/trytond/application.py +++ b/trytond/trytond/application.py @@ -31,11 +31,16 @@ Pool.start() # TRYTOND_CONFIG it's managed by importing config db_names = os.environ.get('TRYTOND_DATABASE_NAMES') if db_names: + from trytond import backend + + def initializer(name): + Pool(name).init() + backend.Database(name).close() # Read with csv so database name can include special chars reader = csv.reader(StringIO(db_names)) threads = [] for name in next(reader): - thread = threading.Thread(target=lambda: Pool(name).init()) + thread = threading.Thread(target=initializer, args=(name,)) thread.start() threads.append(thread) for thread in threads: diff --git a/trytond/trytond/backend/postgresql/database.py b/trytond/trytond/backend/postgresql/database.py index 27968f6940..af4b0c4759 100644 --- a/trytond/trytond/backend/postgresql/database.py +++ b/trytond/trytond/backend/postgresql/database.py @@ -286,7 +286,7 @@ class Database(DatabaseInterface): def close(self): with self._lock: logger.info('disconnection from "%s"', self.name) - self._connpool.close() + self._connpool.close(None) self._databases[os.getpid()].pop(self.name) @classmethod