Move WSGI initialization into module

This commit is contained in:
Unrud 2018-04-20 22:53:42 +02:00
parent 3f9c34c8b1
commit 8b1547cbe5
3 changed files with 26 additions and 23 deletions

View File

@ -26,16 +26,8 @@ WSGI-to-FastCGI mapper.
"""
import os
from flup.server.fcgi import WSGIServer
from radicale import Application, config, log
from radicale import application
config_paths = []
if os.environ.get("RADICALE_CONFIG"):
config_paths.append(os.environ["RADICALE_CONFIG"])
configuration = config.load(config_paths, ignore_missing_paths=False)
filename = os.path.expanduser(configuration.get("logging", "config"))
debug = configuration.getboolean("logging", "debug")
logger = log.start("radicale", filename, debug)
WSGIServer(Application(configuration, logger)).run()
WSGIServer(application).run()

View File

@ -21,15 +21,4 @@ Radicale WSGI file (mod_wsgi and uWSGI compliant).
"""
import os
from radicale import Application, config, log
config_paths = []
if os.environ.get("RADICALE_CONFIG"):
config_paths.append(os.environ["RADICALE_CONFIG"])
configuration = config.load(config_paths, ignore_missing_paths=False)
filename = os.path.expanduser(configuration.get("logging", "config"))
debug = configuration.getboolean("logging", "debug")
logger = log.start("radicale", filename, debug)
application = Application(configuration, logger)
from radicale import application

View File

@ -51,7 +51,7 @@ from xml.etree import ElementTree as ET
import vobject
from radicale import auth, rights, storage, web, xmlutils
from radicale import auth, config, log, rights, storage, web, xmlutils
VERSION = pkg_resources.get_distribution('radicale').version
@ -949,3 +949,25 @@ class Application:
"Bad REPORT request on %r: %s", path, e, exc_info=True)
return BAD_REQUEST
return (status, headers, self._write_xml_content(xml_answer))
_application = None
_application_lock = threading.Lock()
def application(environ, start_response):
global _application
if _application is None:
with _application_lock:
if _application is None:
config_paths = []
if os.environ.get("RADICALE_CONFIG"):
config_paths.append(os.environ["RADICALE_CONFIG"])
configuration = config.load(config_paths,
ignore_missing_paths=False)
filename = os.path.expanduser(configuration.get("logging",
"config"))
debug = configuration.getboolean("logging", "debug")
logger = log.start("radicale", filename, debug)
_application = Application(configuration, logger)
return _application(environ, start_response)