Files
tryton/bin/trytond
T
Cédric Krier cdb19908ee 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
2020-06-06 13:58:32 +02:00

69 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import glob
import logging
import os
import sys
import threading
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
'..', '..', 'trytond')))
if os.path.isdir(DIR):
sys.path.insert(0, os.path.dirname(DIR))
import trytond.commandline as commandline
from trytond.config import config, split_netloc
parser = commandline.get_parser_daemon()
options = parser.parse_args()
commandline.config_log(options)
extra_files = config.update_etc(options.configfile)
if options.coroutine:
# Monkey patching must be done before importing
from gevent import monkey
monkey.patch_all()
# Import trytond things after it is configured
from trytond.wsgi import app
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:
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')
if certificate or privatekey:
from werkzeug.serving import load_ssl_context
ssl_args = dict(
ssl_context=load_ssl_context(certificate, privatekey))
else:
ssl_args = {}
for module in get_module_list():
info = get_module_info(module)
path = os.path.join(info['directory'], 'view', '*.xml')
extra_files.extend(glob.glob(path))
if options.coroutine:
from gevent.pywsgi import WSGIServer
logger = logging.getLogger('gevent')
WSGIServer((hostname, port), app,
log=logger,
error_log=logger,
**ssl_args).serve_forever()
else:
from werkzeug.serving import run_simple
run_simple(hostname, port, app,
threaded=True,
extra_files=extra_files,
use_reloader=options.dev,
**ssl_args)