diff --git a/CHANGELOG b/CHANGELOG index 36116fa97..3cf9a64be 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,9 +2,11 @@ Update pillow requirement to 11.0.0 Update psutil requirement to 6.1.0 Update setuptools requirement to 75.3.0 +Add `pywin32==308` (only for Windows, i.e. `sys_platform=='win32'`) # New Features Added the `character` search option to the `imdb_search` builder +Added the `-ni/--nice` (`KOMETA_NICE=true`) command line argument option to run the process at a lower priority # Defaults Fixed incorrect content rating mappings in various Default files diff --git a/docs/kometa/environmental.md b/docs/kometa/environmental.md index 54d84254c..c28198f5a 100644 --- a/docs/kometa/environmental.md +++ b/docs/kometa/environmental.md @@ -671,6 +671,26 @@ different ways to specify these things. docker run -it -v "X:\Media\Kometa\config:/config:rw" kometateam/kometa --width 150 ``` +??? blank "Nice      `-ni`/`--nice`      `KOMETA_NICE`" + +
Run the Kometa process at a lower priority. Will default to normal priority if not specified. + +
+ + **Shell Flags:** `-ni` or `--nice` (ex. `--nice`) + + **Environment Variable:** `KOMETA_NICE` (ex. `KOMETA_NICE=true`) + + !!! example + === "Local Environment" + ``` + python kometa.py --nice + ``` + === "Docker Environment" + ``` + docker run -it -v "X:\Media\Kometa\config:/config:rw" kometateam/kometa --nice + ``` + ??? blank "Config Secrets      `--kometa-***`      `KOMETA_***`"
All Run Commands that are in the format `--kometa-***` and Environment Variables that are in the diff --git a/kometa.py b/kometa.py index ff5619afb..a79952098 100644 --- a/kometa.py +++ b/kometa.py @@ -70,6 +70,7 @@ "read-only-config": {"args": "ro", "type": "bool", "help": "Run without writing to the config"}, "divider": {"args": "d", "type": "str", "default": "=", "help": "Character that divides the sections (Default: '=')"}, "width": {"args": "w", "type": "int", "default": 100, "help": "Screen Width (Default: 100)"}, + "nice": {"args": "ni", "type": "bool", "help": "Run with lower priority"}, } parser = argparse.ArgumentParser() @@ -257,6 +258,31 @@ def new_send(*send_args, **kwargs): plexapi.BASE_HEADERS["X-Plex-Client-Identifier"] = str(uuid_num) ImageFile.LOAD_TRUNCATED_IMAGES = True +def low_priority(): + """ Set the priority of the process to below-normal.""" + try: + sys.getwindowsversion() + except AttributeError: + isWindows = False + else: + isWindows = True + + if isWindows: + import win32api, win32process + # priorityclasses: + # win32process.IDLE_PRIORITY_CLASS, + # win32process.BELOW_NORMAL_PRIORITY_CLASS, + # win32process.NORMAL_PRIORITY_CLASS, + # win32process.ABOVE_NORMAL_PRIORITY_CLASS, + # win32process.HIGH_PRIORITY_CLASS, + # win32process.REALTIME_PRIORITY_CLASS + win32process.SetPriorityClass(win32api.GetCurrentProcess(), win32process.BELOW_NORMAL_PRIORITY_CLASS) + else: + os.nice(10) + +if run_args["nice"]: + low_priority() + def process(attrs): with ProcessPoolExecutor(max_workers=1) as executor: executor.submit(start, *[attrs]) @@ -284,6 +310,7 @@ def start(attrs): logger.info(f" Platform: {platform.platform()}") logger.info(f" Total Memory: {round(psutil.virtual_memory().total / (1024.0 ** 3))} GB") logger.info(f" Available Memory: {round(psutil.virtual_memory().available / (1024.0 ** 3))} GB") + logger.info(f" Process Priority: {'low' if run_args["nice"] else 'normal'}") if not is_docker and not is_linuxserver: try: with open(os.path.abspath(os.path.join(os.path.dirname(__file__), "requirements.txt")), "r") as file: diff --git a/requirements.txt b/requirements.txt index e16d6a364..2aa6f088a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ tenacity==9.0.0 ruamel.yaml==0.18.6 schedule==1.2.2 setuptools==75.3.0 -tmdbapis==1.2.21 \ No newline at end of file +tmdbapis==1.2.21 +pywin32==308; sys_platform == 'win32'