From cdb19908ee8526a390f42739401fdff610b406e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 6 Jun 2020 13:58:32 +0200 Subject: [PATCH] Wait Pool.init threads before serving In WSGI server that forks the main process, not waiting the end of threads creates a dead lock. issue9377 review311651002 --- bin/trytond | 7 ++++++- trytond/application.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/trytond b/bin/trytond index c6e97136c6..b4877d15a5 100755 --- a/bin/trytond +++ b/bin/trytond @@ -31,8 +31,13 @@ from trytond.pool import Pool from trytond.modules import get_module_list, get_module_info with commandline.pidfile(options): + threads = [] for name in options.database_names: - threading.Thread(target=Pool(name).init).start() + thread = threading.Thread(target=Pool(name).init) + thread.start() + threads.append(thread) + for thread in threads: + thread.join() hostname, port = split_netloc(config.get('web', 'listen')) certificate = config.get('ssl', 'certificate') privatekey = config.get('ssl', 'privatekey') diff --git a/trytond/application.py b/trytond/application.py index 684752b6ee..a59a60907c 100644 --- a/trytond/application.py +++ b/trytond/application.py @@ -34,5 +34,10 @@ db_names = os.environ.get('TRYTOND_DATABASE_NAMES') if db_names: # Read with csv so database name can include special chars reader = csv.reader(StringIO(db_names)) + threads = [] for name in next(reader): - threading.Thread(target=Pool(name).init).start() + thread = threading.Thread(target=Pool(name).init) + thread.start() + threads.append(thread) + for thread in threads: + thread.join()