1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Fix supysonic-server with gunicorn creating the application too early

Was causing SQL connection issues when using forked workers

Closes #241
This commit is contained in:
Alban Féron 2023-01-16 22:10:39 +01:00
parent be6b617e60
commit 36efefcda6
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
5 changed files with 19 additions and 21 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021 Alban 'spl0k' Féron
# Copyright (C) 2021-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -13,7 +13,6 @@ from click import command, option, Option
from click.exceptions import UsageError, ClickException
from click.types import Choice
from ..web import create_application
_servers = [
e.name[:-3]
@ -121,7 +120,6 @@ def main(server, host, port, socket, processes, threads):
host = None
port = None
app = create_application()
server(
app, host=host, port=port, socket=socket, processes=processes, threads=threads
host=host, port=port, socket=socket, processes=processes, threads=threads
).run()

View File

@ -1,19 +1,19 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021 Alban 'spl0k' Féron
# Copyright (C) 2021-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
from abc import ABCMeta, abstractmethod
from ..web import create_application
class BaseServer(metaclass=ABCMeta):
def __init__(
self, app, *, host=None, port=None, socket=None, processes=None, threads=None
self, *, host=None, port=None, socket=None, processes=None, threads=None
):
self._app = app
self._host = host
self._port = port
self._socket = socket
@ -28,5 +28,8 @@ class BaseServer(metaclass=ABCMeta):
def _run(self, **kwargs):
...
def _load_app(self):
return create_application()
def run(self):
self._run(**self._build_kwargs())

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021 Alban 'spl0k' Féron
# Copyright (C) 2021-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -16,7 +16,7 @@ from ._base import BaseServer
class GeventServer(BaseServer):
def _build_kwargs(self):
rv = {"application": self._app}
rv = {"application": self._load_app()}
if self._socket is not None:
if os.path.exists(self._socket):

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021 Alban 'spl0k' Féron
# Copyright (C) 2021-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -11,15 +11,11 @@ from ._base import BaseServer
class GunicornApp(BaseApplication):
def __init__(self, app, **config):
self.__app = app
def __init__(self, **config):
self.__config = config
super().__init__()
def load(self):
return self.__app
def load_config(self):
socket = self.__config["socket"]
host = self.__config["host"]
@ -39,9 +35,10 @@ class GunicornApp(BaseApplication):
class GunicornServer(BaseServer):
def __init__(self, app, **kwargs):
super().__init__(app, **kwargs)
self.__server = GunicornApp(app, **kwargs)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.__server = GunicornApp(**kwargs)
self.__server.load = self._load_app
def _build_kwargs(self):
return {}

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021 Alban 'spl0k' Féron
# Copyright (C) 2021-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -12,7 +12,7 @@ from ._base import BaseServer
class WaitressServer(BaseServer):
def _build_kwargs(self):
rv = {"app": self._app}
rv = {"app": self._load_app()}
if self._host is not None:
rv["host"] = self._host