add: multithread gen assets
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
CREATE_GENERAL_CATEGORY: bool = True
|
CREATE_GENERAL_CATEGORY: bool = True
|
||||||
THUMB_DIMENSION: tuple[int, int] = (200, 200)
|
THUMB_DIMENSION: tuple[int, int] = (200, 200)
|
||||||
|
MAX_THREADS: int = 50
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import os
|
import thread_manager
|
||||||
|
|
||||||
from path import Path
|
from path import Path
|
||||||
|
|
||||||
@ -61,12 +61,16 @@ class Picture():
|
|||||||
return self._profile_file
|
return self._profile_file
|
||||||
|
|
||||||
def gen_thumb(self):
|
def gen_thumb(self):
|
||||||
im = Image.open(self._large.get_absolute_path())
|
def _(_large: Path, _thumb: Path):
|
||||||
im.thumbnail(config.THUMB_DIMENSION)
|
im = Image.open(_large.get_absolute_path())
|
||||||
im.save(self._thumb.get_absolute_path(), "JPEG")
|
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):
|
def gen_small(self):
|
||||||
im = Image.open(self._large.get_absolute_path()).convert("RGB")
|
def _(_large: Path, _small: Path):
|
||||||
im.save(self._small.get_absolute_path(), quality=95, optimize=True)
|
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