rewrite options with click

+ fix cpu count multiprocessing errors
This commit is contained in:
cwilvx
2025-03-23 23:54:13 +03:00
parent bea853fcd3
commit f891c28c2e
14 changed files with 344 additions and 465 deletions
+1 -2
View File
@@ -157,8 +157,7 @@ class CheckArtistImages:
]
# Use number of CPU cores minus 1 to leave one core free for system processes
num_workers = max(1, math.floor(multiprocessing.cpu_count() / 2))
print("num_workers", num_workers)
num_workers = max(1, os.cpu_count() // 2)
with ProcessPoolExecutor(max_workers=num_workers) as executor:
res = list(
+1 -3
View File
@@ -5,12 +5,10 @@ from app.lib.sortlib import sort_folders, sort_tracks
from app.logger import log
from app.models import Folder
from app.serializers.track import serialize_tracks
from app.settings import SUPPORTED_FILES
from app.utils.filesystem import SUPPORTED_FILES
from app.store.folder import FolderStore
from app.utils.wintools import win_replace_slash
# from app.db.libdata import TrackTable as TrackDB
def create_folder(path: str, trackcount=0) -> Folder:
"""
+5 -12
View File
@@ -22,6 +22,7 @@ from app.utils.progressbar import tqdm
from app.db.userdata import SimilarArtistTable
class CordinateMedia:
"""
Cordinates the extracting of thumbnails
@@ -64,22 +65,14 @@ def get_image(album: Album):
:return: None
"""
matching_tracks = AlbumStore.get_album_tracks(album.albumhash)
for track in matching_tracks:
extracted = extract_thumb(track.filepath, track.albumhash + ".webp")
if extracted:
return
def get_cpu_count():
"""
Returns the number of CPUs on the machine.
"""
cpu_count = os.cpu_count() or 0
return cpu_count // 2 if cpu_count > 2 else cpu_count
class ProcessTrackThumbnails:
"""
Extracts the album art from all albums in album store.
@@ -93,7 +86,7 @@ class ProcessTrackThumbnails:
if platform.system() == "Linux":
# INFO: Processess are forked with access to global stores
# It's "safe" to use a process pool
cpus = math.floor(get_cpu_count() / 2)
cpus = max(1, os.cpu_count() // 2)
with ProcessPoolExecutor(max_workers=cpus) as executor:
results = list(
tqdm(
@@ -160,7 +153,7 @@ class FetchSimilarArtistsLastFM:
)
artists = list(artists)
with ProcessPoolExecutor(max_workers=get_cpu_count()) as executor:
with ProcessPoolExecutor(max_workers=max(1, os.cpu_count() // 2)) as executor:
try:
print("Processing similar artists")
results = list(