kthread
Killable threads in Python!
Decision gist · record as of 2026-08-14
No. The package is abandoned (last update 2022-02-19) and comes with explicit warnings that thread termination can cause instability. Modern Python code should use threading.Event, queue.Queue, or async/await for controlled thread shutdown. Install only if you have a specific legacy codebase already using it and cannot refactor to safer patterns.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Threads blocked on OS calls (sleep, socket operations) may not respond to termination.
- The package uses CPython internals and may not work on non-CPython implementations.
- Installation is straightforward with no runtime dependencies.
License · maintenance · safety
permissive license (permissive) — MIT license permits free use, modification, and distribution with minimal restrictions, making it legally safe to integrate into most projects.
last release 2022-02-19 (1637 days) · last repo commit 2022-02-19 · 16 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 89,985 downloads/mo, #13,626 on PyPI
Alternatives
Verify before relying
import time
import kthread
def worker():
while True:
time.sleep(0.2)
t = kthread.KThread(target=worker)
t.start()
t.terminate() # or t.kill() or t.exit()- Whether the CPython API approach works reliably across Python 3.x versions beyond what the classifiers claim
- Specific Python versions where OS-blocked threads (sleep, accept, recv) cannot be interrupted
- Compatibility with async/await patterns or modern concurrency libraries
What it is and what it does
KThread is a thin wrapper around Python's threading.Thread that adds methods to forcefully terminate a running thread by injecting a SystemExit exception via the CPython API. It solves the problem that the standard library offers no built-in way to stop a thread once started—you can only wait for it to finish naturally.
The package works by leveraging low-level CPython internals to raise an exception inside a target thread. Threads blocked on OS calls (like time.sleep, socket.accept, or socket.recv) will not respond to termination. The author includes a strong disclaimer that thread termination can introduce instability, resource leaks, or other undesirable effects, and provides no warranty. It is intended for cases where you have no other way to stop a thread and accept the risks.
Use it for
- Stopping long-running worker threads when a parent process receives a shutdown signal
- Cleaning up threads that enter infinite loops and cannot be interrupted by normal means
- Testing code that spawns threads, where you need to forcibly halt them between test cases
- Implementing timeout mechanisms for thread-based operations when standard timeout patterns are unavailable
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
No.
The package is abandoned (last update 2022-02-19) and comes with explicit warnings that thread termination can cause instability. Modern Python code should use threading.Event, queue.Queue, or async/await for controlled thread shutdown. Install only if you have a specific legacy codebase already using it and cannot refactor to safer patterns.
Install
kthread on PyPI
Before you install
Installation is straightforward with no runtime dependencies. However, the package is abandoned—last release was 2022-02-19 with no updates since, and the repository shows minimal activity (16 stars). Use only if you accept the maintenance risk.
Threads blocked on OS calls (sleep, socket operations) may not respond to termination. The package uses CPython internals and may not work on non-CPython implementations.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions, making it legally safe to integrate into most projects.
Quickstart
import time
import kthread
def worker():
while True:
time.sleep(0.2)
t = kthread.KThread(target=worker)
t.start()
t.terminate() # or t.kill() or t.exit()
Verify before relying
- Whether the CPython API approach works reliably across Python 3.x versions beyond what the classifiers claim
- Specific Python versions where OS-blocked threads (sleep, accept, recv) cannot be interrupted
- Compatibility with async/await patterns or modern concurrency libraries
Package facts
| License | permissive license permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Abandoned 1,637 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 89,985 / month, #13,626 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 2.7Programming Language :: Python :: 3 |
Evidence: kthread-0.2.3-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “kill thread python”
- kthreadKThread provides a way to forcefully terminate running threads by…
- aa-killstatsA Django module for AllianceAuth that tracks and displays EVE Online…
- django-pgactivityProvides Django management commands and utilities to view, filter,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also func-timeout · threaded · stopit · pytest-reraise · Flask-Threads · simpervisor · lib-cli-exit-tools · pytest-threadleak · opentelemetry-instrumentation-threading · pytest-run-parallel