Skip to main content

⏰ process-time-killer

Project description

⏰ Process Time Killer

process-time-killer is a Python utility to run subprocesses and terminate them after a specified timeout. This package helps in controlling processes by running commands for a limited time and ensuring they are terminated gracefully or forcefully.

Features

  • Run any subprocess for a specified duration.
  • Automatically terminate the subprocess after a given timeout.
  • Graceful termination or forced killing if the process does not exit on time.
  • Logs all steps, including the start, termination attempt, and any errors.

Installation

You can install process-time-killer via pip:

pip install process-time-killer

Usage

Command-line Interface (CLI)

Run the utility from the command line by specifying the command and an optional timeout:

timekiller "ping google.com" --timeout 10

Arguments:

  • command: The command to run in the subprocess (default: "ping google.com").
  • --timeout: Time in seconds before the subprocess is terminated (default: 12 seconds).

Example:

Run the echo command for 5 seconds:

timekiller "echo Hello World" --timeout 5

Programmatic Usage

You can also use this utility in your Python code by calling the run_subprocess function:

from timekiller import run_subprocess

command = "echo Hello World"
timeout = 10

run_subprocess(command, timeout)

Functions

run_subprocess(command: str, seconds: int)

Runs a subprocess with the specified command and terminates it after the given number of seconds.

Arguments:

  • command (str): The command to execute in the subprocess.
  • seconds (int): Number of seconds to run the subprocess before terminating.

Raises:

  • ValueError: If the command or seconds parameter is invalid.
  • RuntimeError: If there is an issue with starting or terminating the subprocess.

main()

The main function that serves as the entry point for the command-line interface (CLI). It parses the arguments and calls run_subprocess.

Logging

This package uses Python’s built-in logging module to log: • The start of the subprocess. • The attempt to terminate the subprocess after the timeout. • Any errors that occur during execution.

License

This project is licensed under the MIT License.

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

process_time_killer-0.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

process_time_killer-0.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file process_time_killer-0.2.tar.gz.

File metadata

  • Download URL: process_time_killer-0.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.11

File hashes

Hashes for process_time_killer-0.2.tar.gz
Algorithm Hash digest
SHA256 3630ce9e7ae57021afc056d7dcdef15d59e43efee604e5a9d882da688236451d
MD5 a49f1e9389e7ca22208a645dd64e8772
BLAKE2b-256 cb6d79c67348023ca8dc5bb0338f1dc44639af6bce0f1d47a68d6507f5bc68a8

See more details on using hashes here.

File details

Details for the file process_time_killer-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for process_time_killer-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1e99a2b27765722037b79c7435f7e3e667540294c4c3eda6b06f4eb489920120
MD5 582e0bfa1fe5138196e6c47b01640af6
BLAKE2b-256 9e178a78c1c1c2702be33eb362249c89ffb0bc71629106de85d4b2403a9761e0

See more details on using hashes here.

Supported by

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