File: application.py

package info (click to toggle)
tryton-server 7.0.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,748 kB
  • sloc: python: 53,502; xml: 5,194; sh: 803; sql: 217; makefile: 28
file content (43 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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 csv
import logging.config
import os
import threading
from io import StringIO

__all__ = ['app']

# Logging must be set before importing
logging_config = os.environ.get('TRYTOND_LOGGING_CONFIG')
logging_level = int(os.environ.get(
        'TRYTOND_LOGGING_LEVEL', default=logging.ERROR))
if logging_config:
    logging.config.fileConfig(logging_config)
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)

if os.environ.get('TRYTOND_COROUTINE'):
    from gevent import monkey
    monkey.patch_all()

from trytond.pool import Pool  # noqa: E402
from trytond.wsgi import app  # noqa: E402

Pool.start()
# 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
    reader = csv.reader(StringIO(db_names))
    threads = []
    for name in next(reader):
        thread = threading.Thread(target=Pool(name).init)
        thread.start()
        threads.append(thread)
    for thread in threads:
        thread.join()