details: https://code.tryton.org/tryton/commit/f6a9d62f1dbf
branch: 8.0
user: Cédric Krier <[email protected]>
date: Tue May 19 18:19:59 2026 +0200
description:
Close database after initialization of Pool from WSGI application
The psycopg pool starts worker threads that must be stopped.
Closes #14849
(grafted from fb2059f652653820142d67f34fd58953decf48f3)
diffstat:
trytond/trytond/application.py | 7 ++++++-
trytond/trytond/backend/postgresql/database.py | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)
diffs (33 lines):
diff -r 480eeda38b22 -r f6a9d62f1dbf trytond/trytond/application.py
--- a/trytond/trytond/application.py Tue May 19 12:29:44 2026 +0200
+++ b/trytond/trytond/application.py Tue May 19 18:19:59 2026 +0200
@@ -31,11 +31,16 @@
# 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 -r 480eeda38b22 -r f6a9d62f1dbf
trytond/trytond/backend/postgresql/database.py
--- a/trytond/trytond/backend/postgresql/database.py Tue May 19 12:29:44
2026 +0200
+++ b/trytond/trytond/backend/postgresql/database.py Tue May 19 18:19:59
2026 +0200
@@ -286,7 +286,7 @@
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