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.1.14.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.1.14-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: process_time_killer-0.1.14.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.1.14.tar.gz
Algorithm Hash digest
SHA256 ae370c733f2efaa847f2d2e9ddf56eb0c866cc6b5a7c8cb9a9dc0f8912cf5f57
MD5 54c60205cdf187bd86f16a4980201e74
BLAKE2b-256 400f1259f1e78cc06525d30b309a63e6ea86741db2f681e61107c79b7c918601

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for process_time_killer-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 331e9795100967b1f047318d24bcf20a8354514282305542119a30e194f04c5b
MD5 610c3d7b309347e4cd052935c5ceaf4d
BLAKE2b-256 48ae829046b281aba2152f65bd7ff660a62d5a38e748d8f7605681b09208cb21

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