2016-03-15 16:57:26 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2017-07-19 10:10:04 +02:00
|
|
|
import csv
|
|
|
|
|
import os
|
|
|
|
|
import logging.config
|
2019-06-16 19:19:30 +02:00
|
|
|
import threading
|
2017-07-19 10:10:04 +02:00
|
|
|
from io import StringIO
|
2016-03-15 16:57:26 +01:00
|
|
|
|
|
|
|
|
__all__ = ['app']
|
|
|
|
|
|
2017-07-19 10:10:04 +02:00
|
|
|
# Logging must be set before importing
|
|
|
|
|
logging_config = os.environ.get('TRYTOND_LOGGING_CONFIG')
|
2019-07-23 00:09:25 +02:00
|
|
|
logging_level = int(os.environ.get(
|
|
|
|
|
'TRYTOND_LOGGING_LEVEL', default=logging.ERROR))
|
2017-07-19 10:10:04 +02:00
|
|
|
if logging_config:
|
|
|
|
|
logging.config.fileConfig(logging_config)
|
2019-07-23 00:09:25 +02:00
|
|
|
else:
|
|
|
|
|
logformat = ('%(process)s %(thread)s [%(asctime)s] '
|
|
|
|
|
'%(levelname)s %(name)s %(message)s')
|
|
|
|
|
level = max(logging_level, logging.NOTSET)
|
|
|
|
|
logging.basicConfig(level=level, format=logformat)
|
|
|
|
|
logging.captureWarnings(True)
|
2017-07-19 10:10:04 +02:00
|
|
|
|
2019-02-05 19:09:53 +01:00
|
|
|
if os.environ.get('TRYTOND_COROUTINE'):
|
|
|
|
|
from gevent import monkey
|
|
|
|
|
monkey.patch_all()
|
|
|
|
|
|
2020-03-01 12:33:54 +01:00
|
|
|
from trytond.pool import Pool # noqa: E402
|
|
|
|
|
from trytond.wsgi import app # noqa: E402
|
2017-07-19 10:10:04 +02:00
|
|
|
|
2016-03-15 16:57:26 +01:00
|
|
|
Pool.start()
|
2017-07-19 10:10:04 +02:00
|
|
|
# TRYTOND_CONFIG it's managed by importing config
|
|
|
|
|
db_names = os.environ.get('TRYTOND_DATABASE_NAMES')
|
|
|
|
|
if db_names:
|
|
|
|
|
# Read with csv so database name can include special chars
|
2018-06-26 19:11:19 +02:00
|
|
|
reader = csv.reader(StringIO(db_names))
|
2020-06-06 13:58:32 +02:00
|
|
|
threads = []
|
2019-06-16 19:19:30 +02:00
|
|
|
for name in next(reader):
|
2020-06-06 13:58:32 +02:00
|
|
|
thread = threading.Thread(target=Pool(name).init)
|
|
|
|
|
thread.start()
|
|
|
|
|
threads.append(thread)
|
|
|
|
|
for thread in threads:
|
|
|
|
|
thread.join()
|