Skip to main content

Convenient and customizable solution for monitoring and terminating processes - Windows only

Project description

Convenient and customizable solution for monitoring and terminating processes - Windows only

pip install constant-check-and-kill

Tested against Windows 10 / Python 3.10 / Anaconda

The constant_check_and_kill module provides a convenient and customizable solution for monitoring and terminating processes, offering users greater control and automation in managing their system's processes.

It can be useful for system administrators, developers, or users who need to monitor and terminate specific processes based on configurable criteria. Here are some potential use cases and advantages of using this module:

Flexibility:

The module provides configurable options such as executable path patterns, regular expression support, and delay between process checks, allowing users to tailor the process monitoring and termination behavior to their specific needs.

Automation:

The module allows for continuous monitoring and automatic termination of processes, reducing the need for manual intervention and saving time.

Customization:

Users can define their own process termination criteria based on executable path patterns or regular expressions, giving them fine-grained control over which processes to target.

Scalability:

The module can handle multiple processes simultaneously, making it suitable for environments with a large number of processes to monitor and terminate.

Control:

Users can choose to terminate only the first matching process or continue monitoring and terminating subsequent matches, providing flexibility in managing process termination behavior.

constant_check_and_kill(
    exe_path: str | None = None,
    is_regex: int | bool = 1,
    flags: int = re.I,
    delay: float | int = 1.0,
    close_after_first: int | bool = 0,
):
    r"""
    Continuously checks for running processes and kills them if they match the specified criteria.

    Args:
        exe_path (str | None): The path or regex pattern of the processes to be killed.
        is_regex (int | bool): Flag indicating if `exe_path` is a regex pattern (default: 1).
        flags (int): Additional flags for the regex pattern matching (default: re.I).
        delay (float | int): Delay in seconds between process checks (default: 1.0).
        close_after_first (int | bool): Flag indicating whether to exit after killing the first matching process (default: 0).

    Returns:
        Callable[[], None]: A partial function that can be used to stop the continuous process checking and killing.

    Raises:
        None

    Example usage:

    Killing one process - function call:
    This example demonstrates how to kill a single process by calling the kill_proc function with the desired process ID (PID).
    The process with the specified PID will be terminated.

    kill_proc(pid=21360)
    ############################################################
    Constantly checking if processes exist and kill them - CLI:
    This example shows how to use the script from the command line to continuously monitor and kill processes that match a
    specific executable path pattern. The command should be executed in the following format:

    python .\constant_kill_procs.py --exe_path "(?:calculator.exe|chrome.exe)$" --is_regex 1 --flags 2 --delay 0.1 --close_after_first 0
    --exe_path: The regular expression pattern specifying the executable path(s) of the target processes.
    --is_regex: A flag indicating whether the exe_path argument should be treated as a regular expression (1 for True, 0 for False).
    --flags: Additional flags for the regular expression pattern matching.
    --delay: The delay in seconds between each process check.
    --close_after_first: A flag indicating whether to exit the script after killing the first matching process (1 for True, 0 for False).
    ############################################################
    Constantly checking if processes exist and kill them - function call:
    This example demonstrates how to continuously monitor and kill processes that match a specific executable path pattern
    by calling the constant_check_and_kill function directly.
    from constant_check_and_kill import constant_check_and_kill

    constant_check_and_kill(
        exe_path="notepad.exe$",
        is_regex=True,
        flags=re.I,
        delay=1.0,
        close_after_first=False,
    )
    exe_path: The regular expression pattern or exact executable path of the target processes.
    is_regex: A flag indicating whether the exe_path argument should be treated as a regular expression (True) or an exact path (False).
    flags: Additional flags for the regular expression pattern matching.
    delay: The delay in seconds between each process check.
    close_after_first: A flag indicating whether to exit the script after killing the first matching process (True) or
    continue monitoring and killing other matching processes (False).

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

constant_check_and_kill-0.10.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

constant_check_and_kill-0.10-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for constant_check_and_kill-0.10.tar.gz
Algorithm Hash digest
SHA256 33e4afdb11d694010622c53e85fa9cf41d8e433374f574c6abda3f94ca9f29aa
MD5 c2c32ad8525272291b14aa6992390944
BLAKE2b-256 a36e34f7979736665fc643d90aab9793ac469a350f12d97ea9eed4e868dda948

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for constant_check_and_kill-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cb17cfc1fc6809871030c8d8c7340ba03e441a11d36e04e415d8baed5bab19f2
MD5 a9ba304f9a8019ee824f81911327baf8
BLAKE2b-256 da679c724f5084e989a975842c108c51a2f4969bb4b5e4cef66c879bd2207c6f

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