mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
fix: multiprocessing problems
This commit is contained in:
+26
-2
@@ -1,7 +1,9 @@
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from sqlalchemy import Engine, event
|
from sqlalchemy import Engine, create_engine, event
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
from app.settings import DbPaths
|
||||||
|
|
||||||
|
|
||||||
@event.listens_for(Engine, "connect")
|
@event.listens_for(Engine, "connect")
|
||||||
def set_sqlite_pragma(dbapi_connection, connection_record):
|
def set_sqlite_pragma(dbapi_connection, connection_record):
|
||||||
@@ -14,13 +16,35 @@ def set_sqlite_pragma(dbapi_connection, connection_record):
|
|||||||
cursor.execute("PRAGMA mmap_size=0")
|
cursor.execute("PRAGMA mmap_size=0")
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
class classproperty(property):
|
||||||
|
"""
|
||||||
|
A class property decorator.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __get__(self, owner_self, owner_cls):
|
||||||
|
if self.fget:
|
||||||
|
return self.fget(owner_cls)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DbEngine:
|
class DbEngine:
|
||||||
"""
|
"""
|
||||||
The database engine instance.
|
The database engine instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
engine: Engine
|
_engine: Engine | None = None
|
||||||
|
|
||||||
|
@classproperty
|
||||||
|
def engine(cls) -> Engine:
|
||||||
|
if not cls._engine:
|
||||||
|
cls._engine = create_engine(
|
||||||
|
f"sqlite+pysqlite:///{DbPaths.get_app_db_path()}",
|
||||||
|
echo=False,
|
||||||
|
max_overflow=20,
|
||||||
|
pool_size=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
return cls._engine
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import math
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import random
|
||||||
import urllib
|
import urllib
|
||||||
import requests
|
import requests
|
||||||
import multiprocessing
|
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -29,8 +28,6 @@ LARGE_ENOUGH_NUMBER = 100
|
|||||||
PngImagePlugin.MAX_TEXT_CHUNK = LARGE_ENOUGH_NUMBER * (1024**2)
|
PngImagePlugin.MAX_TEXT_CHUNK = LARGE_ENOUGH_NUMBER * (1024**2)
|
||||||
# https://stackoverflow.com/a/61466412
|
# https://stackoverflow.com/a/61466412
|
||||||
|
|
||||||
import random
|
|
||||||
|
|
||||||
|
|
||||||
def get_artist_image_link(artist: str):
|
def get_artist_image_link(artist: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ class IndexTracks:
|
|||||||
extract_thumb(
|
extract_thumb(
|
||||||
track["filepath"], track["albumhash"] + ".webp", overwrite=True
|
track["filepath"], track["albumhash"] + ".webp", overwrite=True
|
||||||
)
|
)
|
||||||
except FileNotFoundError:
|
except (FileNotFoundError, KeyError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
+5
-1
@@ -29,7 +29,11 @@ class Paths:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_config_dir(cls):
|
def get_config_dir(cls):
|
||||||
return cls.XDG_CONFIG_DIR or os.path.realpath(".")
|
return (
|
||||||
|
cls.XDG_CONFIG_DIR
|
||||||
|
or os.environ.get("SWINGMUSIC_XDG_CONFIG_DIR")
|
||||||
|
or os.path.realpath(".")
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_config_folder(cls):
|
def get_config_folder(cls):
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ def setup_sqlite():
|
|||||||
"""
|
"""
|
||||||
Create Sqlite databases and tables.
|
Create Sqlite databases and tables.
|
||||||
"""
|
"""
|
||||||
DbEngine.engine = create_engine(
|
DbEngine._engine = create_engine(
|
||||||
f"sqlite+pysqlite:///{DbPaths.get_app_db_path()}",
|
f"sqlite+pysqlite:///{DbPaths.get_app_db_path()}",
|
||||||
echo=False,
|
echo=False,
|
||||||
max_overflow=20,
|
max_overflow=20,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import multiprocessing
|
import os
|
||||||
import pathlib
|
|
||||||
import click
|
|
||||||
import sys
|
import sys
|
||||||
|
import click
|
||||||
|
import pathlib
|
||||||
|
import multiprocessing
|
||||||
from app.arg_handler import handle_build, handle_password_reset
|
from app.arg_handler import handle_build, handle_password_reset
|
||||||
from app.utils.filesystem import get_home_res_path
|
from app.utils.filesystem import get_home_res_path
|
||||||
from app.utils.xdg_utils import get_xdg_config_dir
|
from app.utils.xdg_utils import get_xdg_config_dir
|
||||||
@@ -66,6 +67,10 @@ def version(*args, **kwargs):
|
|||||||
is_eager=True,
|
is_eager=True,
|
||||||
)
|
)
|
||||||
def run(*args, **kwargs):
|
def run(*args, **kwargs):
|
||||||
|
# INFO: Set the config dir as an environment variable
|
||||||
|
os.environ["SWINGMUSIC_XDG_CONFIG_DIR"] = str(
|
||||||
|
pathlib.Path(kwargs["config"]).resolve()
|
||||||
|
)
|
||||||
run_app(kwargs["host"], kwargs["port"], kwargs["config"])
|
run_app(kwargs["host"], kwargs["port"], kwargs["config"])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user