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
This commit is contained in:
Cédric Krier
2026-05-19 18:19:59 +02:00
parent 4fca529235
commit 5a38f2a853
2 changed files with 7 additions and 2 deletions
+6 -1
View File
@@ -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:
@@ -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