Skip to main content

Constantly checks and changes the priority of processes based on the provided parameters - Windows only

Project description

A flexible and convenient solution for managing process priorities - Windows only

pip install change-proc-priority

Tested against Windows 10 / Python 3.10 / Anaconda

This module offers a flexible and convenient solution for managing process priorities, making it valuable for system administrators, performance optimizers, developers, and researchers who need to fine-tune resource allocation and optimize system performance

Process Priority Control:

The module provides functionality to monitor and change the priority of processes running on a system. This can be useful in scenarios where fine-tuning the priority of specific processes can have a significant impact on system performance or resource allocation.

Constant Monitoring:

The constant_check_and_change_priority function allows for continuous monitoring of processes, ensuring that the desired priority is maintained even if processes are created or terminated dynamically.

Regular Expression Support:

The module supports using regular expressions to specify the executable path of the target processes. This provides flexibility in defining patterns and allows for more complex matching criteria.

CLI and Function Interface:

The module can be utilized both through the command line interface (CLI) and by directly calling the constant_check_and_change_priority function in Python code. This provides versatility in how the module can be incorporated into different workflows and automation processes.

Customizable Parameters:

The module allows for customization of various parameters such as priority, delay between checks, and the ability to close the program after the first matching process is found. This flexibility enables users to tailor the behavior of the module according to their specific requirements.

constant_check_and_change_priority(
    exe_path: str | None = None,
    priority: int = NORMAL,
    is_regex: int | bool = 1,
    flags: int = re.I,
    delay: float | int = 1.0,
    close_after_first: int | bool = 0,
):
    r"""
    Constantly checks and changes the priority of processes based on the provided parameters.

    Args:
        exe_path (str | None): Path or regular expression pattern of the executable to monitor.
        priority (int): Priority value to set for the processes. Valid options are:
            - LOW = 64
            - BELOW_NORMAL = 16384
            - NORMAL = 32
            - ABOVE_NORMAL = 32768
            - HIGH = 128
            - REALTIME = 256
            Defaults to NORMAL (32).
        is_regex (int | bool): Flag indicating whether the exe_path should be treated as a regular expression pattern.
            Defaults to 1 (True).
        flags (int): Flags to be used with the regular expression pattern. Defaults to re.I (ignore case).
        delay (float | int): Delay in seconds between each check. Defaults to 1.0.
        close_after_first (int | bool): Flag indicating whether to exit the program after the first process is found.
            Defaults to 0 (False).

    Returns:
        Callable: A function that can be used to stop the monitoring thread.

    Example:
        Changing priority of one process - function call:
        This line shows an example of calling the change_priority function to change the priority of a specific process
        with a given PID. In this case, the priority is set to HIGH. The PID used here is 21360.

        change_priority(pid=21360,priority=HIGH)
        #################################################
        Constantly changing priority of processes with exe_path - CLI:
        This line demonstrates how to use the script from the command line interface (CLI)
        to constantly monitor and change the priority of processes based on the specified exe_path parameter.
        The script is invoked using the python command, followed by the script path.
        The CLI arguments are provided using -- followed by the argument name and its corresponding value.
        In this example, the exe_path is set to notepad.exe$, the priority is set to 128 (which corresponds
        to HIGH priority), is_regex is set to 1 (True), flags is set to 2, delay is set to 2.0 seconds,
        and close_after_first is set to 0 (False).

        # adjust the path!
        python .\__init__.py --exe_path notepad.exe$ --priority 128 --is_regex 1 --flags 2 --delay 2.0 --close_after_first 0
        #################################################


        This part showcases an example of using the constant_check_and_change_priority function directly in Python code.
        The function is called with various parameters to monitor and change the priority of processes.
        In this example, the exe_path is set to "notepad.exe$", indicating a regular expression pattern,
        the priority is set to NORMAL, is_regex is set to True, flags is set to re.I (ignore case),
        delay is set to 1.0 second, and close_after_first is set to False.
		
		from change_proc_priority import constant_check_and_change_priority
        stop_monitoring=constant_check_and_change_priority(
        exe_path="notepad.exe$",
        priority=NORMAL,
        is_regex=True,
        flags=re.I,
        delay=1.0,
        close_after_first=False,
        )
        #################################################

        # To stop the monitoring thread, call the returned function
        stop_monitoring()
    """

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

change_proc_priority-0.10.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

change_proc_priority-0.10-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file change_proc_priority-0.10.tar.gz.

File metadata

  • Download URL: change_proc_priority-0.10.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for change_proc_priority-0.10.tar.gz
Algorithm Hash digest
SHA256 01d5b8ce3c1861b4a687d552a7dfcf4b4b924d033ff5928f3f579a5410924f50
MD5 98ebd3402e78914d10fbc11c7f038d69
BLAKE2b-256 1f839734ec43ceb2549c9945bed37bdf108186f7d8b9c1aecd5b71bc8fa24927

See more details on using hashes here.

File details

Details for the file change_proc_priority-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for change_proc_priority-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b50d945d0a94d43c0fe634d0ba332da6129948a3921e1b8ac7a198e7b8eb2c
MD5 7979a12ca71a4bbaa29986c55a4e3c62
BLAKE2b-256 5f1b34862850e509006979c11c4d74f9271ba551e4463bf90df5533b2c12959d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page