1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00
supysonic/supysonic/server/gunicorn.py
Alban Féron 36efefcda6
Fix supysonic-server with gunicorn creating the application too early
Was causing SQL connection issues when using forked workers

Closes #241
2023-01-16 22:10:39 +01:00

51 lines
1.3 KiB
Python

# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
from gunicorn.app.base import BaseApplication
from ._base import BaseServer
class GunicornApp(BaseApplication):
def __init__(self, **config):
self.__config = config
super().__init__()
def load_config(self):
socket = self.__config["socket"]
host = self.__config["host"]
port = self.__config["port"]
processes = self.__config["processes"]
threads = self.__config["threads"]
if socket is not None:
self.cfg.set("bind", f"unix:{socket}")
else:
self.cfg.set("bind", f"{host}:{port}")
if processes is not None:
self.cfg.set("workers", processes)
if threads is not None:
self.cfg.set("threads", threads)
class GunicornServer(BaseServer):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.__server = GunicornApp(**kwargs)
self.__server.load = self._load_app
def _build_kwargs(self):
return {}
def _run(self, **kwargs):
return self.__server.run()
server = GunicornServer