add: multithread gen assets
This commit is contained in:
@ -2,3 +2,4 @@
|
||||
|
||||
CREATE_GENERAL_CATEGORY: bool = True
|
||||
THUMB_DIMENSION: tuple[int, int] = (200, 200)
|
||||
MAX_THREADS: int = 50
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
import thread_manager
|
||||
|
||||
from path import Path
|
||||
|
||||
@ -61,12 +61,16 @@ class Picture():
|
||||
return self._profile_file
|
||||
|
||||
def gen_thumb(self):
|
||||
im = Image.open(self._large.get_absolute_path())
|
||||
im.thumbnail(config.THUMB_DIMENSION)
|
||||
im.save(self._thumb.get_absolute_path(), "JPEG")
|
||||
def _(_large: Path, _thumb: Path):
|
||||
im = Image.open(_large.get_absolute_path())
|
||||
im.thumbnail(config.THUMB_DIMENSION)
|
||||
im.save(_thumb.get_absolute_path(), "JPEG")
|
||||
thread_manager.add_to_queu(_, (self._large, self._thumb))
|
||||
|
||||
def gen_small(self):
|
||||
im = Image.open(self._large.get_absolute_path()).convert("RGB")
|
||||
im.save(self._small.get_absolute_path(), quality=95, optimize=True)
|
||||
def _(_large: Path, _small: Path):
|
||||
im = Image.open(_large.get_absolute_path()).convert("RGB")
|
||||
im.save(_small.get_absolute_path(), quality=95, optimize=True)
|
||||
thread_manager.add_to_queu(_, (self._large, self._small))
|
||||
|
||||
|
8
src/thread_manager.py
Normal file
8
src/thread_manager.py
Normal file
@ -0,0 +1,8 @@
|
||||
import concurrent.futures
|
||||
import config
|
||||
|
||||
_pool = concurrent.futures.ThreadPoolExecutor(max_workers=config.MAX_THREADS)
|
||||
|
||||
def add_to_queu(func: callable, args: tuple):
|
||||
global _pool
|
||||
_pool.submit(func, *args)
|
Reference in New Issue
Block a user