Close database after initialization of Pool from WSGI application
The psycopg pool starts worker threads that must be stopped. Closes #14849
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user