A Python utility to gracefully terminate a process and all its child processes
Reason this release was yanked:
deprecated
Project description
kill-process-tree
A Python utility to gracefully terminate a process and all its child processes (the process tree).
Features
- Recursive termination: Kills a parent process and all its descendants
- Graceful shutdown: Attempts to terminate processes cleanly before force-killing
- Error handling: Handles edge cases like already-exited processes and permission issues
- Configurable logging: Enable debug logs via environment variable
Installation
Install from the repository:
pip install .
Or using uv:
uv pip install .
Usage
As a Python module
Run the package directly from the command line:
python3 -m kill_process_tree 1234
To see help:
python3 -m kill_process_tree --help
As a Python function
from kill_process_tree import kill_process_tree
# Kill process with PID 1234 and all its children
kill_process_tree(1234)
Debugging with Logs
Enable debug logging to see detailed information about the termination process:
KILL_PROCESS_TREE_LOG=DEBUG python3 -m kill_process_tree 1234
Log Levels
Control the logging level with the KILL_PROCESS_TREE_LOG environment variable:
KILL_PROCESS_TREE_LOG=DEBUG python3 -m kill_process_tree 1234
If the environment variable is not set, logging is disabled by default.
How It Works
- Snapshot children: Gets a snapshot of all child processes recursively
- Terminate children first: Sends
SIGTERMto all child processes (in reverse order) - Wait for graceful shutdown: Waits up to 3 seconds for processes to exit cleanly
- Force-kill stubborn processes: Sends
SIGKILLto any processes that didn't exit - Terminate parent: Finally terminates (and if needed, kills) the parent process
Error Handling
The function gracefully handles:
- Processes that disappear before they can be terminated
- Access denied errors when lacking permissions
- Timeout errors during graceful shutdown
Requirements
- Python 3.12+
psutillibrary
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kill_process_tree-0.1.0.tar.gz.
File metadata
- Download URL: kill_process_tree-0.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94b049978c7579ee38a4406e5ae231125f5655da7ed7a77b6b1d6d802e50ebaa
|
|
| MD5 |
7b65ee01e73984051623d2526179d91f
|
|
| BLAKE2b-256 |
65c6300154f1745904dc2ddb4d238d955863f91def8c859ccc65692b3e55f979
|
File details
Details for the file kill_process_tree-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kill_process_tree-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6336a445a3ac7aa10a72c407fced387595357dd6536ad4a7b56c38872988d5a
|
|
| MD5 |
fa89fb707c2d71920c3771b8880af8b6
|
|
| BLAKE2b-256 |
06054f8cc3507e6453c4011a571ae727b851f133a55f85d3e36823ad7bf740e8
|