kthread
Killable threads in Python!
Purpose
The built-in threading.Thread class offers no simple solution to terminate a running thread. kthread.KThread inherits threading.Thread and supplies methods named exit(), kill(), and terminate() that serve the same purpose: attempt to stop a thread if it's running.
How it works
KThread leverages the CPython API to raise a SystemExit exception on a given thread. Assuming that the thread is not blocked by an operating system call (such as sleep, accept, or recv), the thread will forcefully quit.
DISCLAIMER
TERMINATING THREADS MAY INTRODUCE INSTABILITY OR OTHER UNDESIRABLE EFFECTS IN YOUR PROGRAMS. THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY. THE MUNSHI GROUP CANNOT BE HELD LIABLE FOR ANY DAMAGES, LOSSES, OR EXPENSES INCURRED BY YOU OR YOUR ORGANIZATION WHILE USING THIS SOFTWARE.
Installation
To install this package, run the following command:
$ pip install kthread
Usage
>>> import time
>>> import kthread
>>> import sys
>>> def func():
>>> try:
>>> while True:
>>> time.sleep(0.2)
>>> finally:
>>> sys.stdout.write("Greetings from Vice City!\n")
>>> sys.stdout.flush()
>>>
>>> t = kthread.KThread(target = func, name = "KillableThread1")
>>> t.start()
>>> t.isAlive()
True
>>> t.terminate()
Greetings from Vice City!
>>> t.isAlive()
False
License
MIT
Metadata
Release files for kthread 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kthread-0.2.3.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kthread-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / kthread-0.2.3.tar.gz
| Download URL | kthread-0.2.3.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90e194e6a7ff903040c4133d3ea9037c908c4296bf5f582c7fdcf6325a04f9b4
|
|
BLAKE2b-256 checksum How to use checksums |
189baa1b48c3cf6e1a914ee5eee1fed77cd7217fb0a35c07c345da4ec5215cae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Release files / kthread-0.2.3-py3-none-any.whl
| Download URL | kthread-0.2.3-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
808d3bb0ec6d573c8a00c10dfabe81b7e87d4ac945cb58335432c17f8db78ca6
|
|
BLAKE2b-256 checksum How to use checksums |
82e34c26efac0a7e4e053eb0042164f3ea7cdee8dfc7eecda521e6d00ce45ea1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|