--- id: kthread version: "0.2.3" license: unclear license_treatment: permissive maintenance: abandoned --- # kthread — Killable threads in Python! License: permissive · Maintenance: abandoned · Downloads: 90.0K/mo ## 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 above — verify before relying. KThread provides a way to forcefully terminate running threads by raising a SystemExit exception within them, extending Python's standard threading.Thread class with kill(), terminate(), and exit() methods. 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 pip install kthread uv add kthread poetry add kthread ## Installing kthread 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. 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() 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. 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: not declared (permissive) - Python support: unspecified - Install friction: low - Maintenance: abandoned - Downloads: 90.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags kill thread python, terminate thread forcefully, stop running thread, thread termination, killable threads, thread exit, force thread stop, threading, legacy-maintenance-risk [View on SkillFed](https://skillfed.io/packages/kthread) · [View on PyPI](https://pypi.org/project/kthread/)