A utility to manage and kill threads in Python applications.
PyThreadKiller
is a utility designed to manage and kill threads in Python applications. This package provides a simple and effective way to terminate threads safely and retrieve return values from target functions.
PyThreadKiller/
├── PyThreadKiller/
│ ├── __init__.py
│ ├── main.py
├── tests/
│ ├── TestPyThreadKiller.py
│ ├── UnittestPyThreadKiller.py
├── CHANGELOG.md
├── README.md
├── requirements.txt
├── .github/
│ └── workflows/
│ └── python-app.yml
└── setup.py
You can install the package using pip:
pip install PyThreadKiller
- Here is an example of how to use PyThreadKiller:
import time
from PyThreadKiller import PyThreadKiller
def example_target():
for i in range(5):
print(f"Thread is running... {i}")
time.sleep(1)
return True
# Create an instance of PyThreadKiller
thread = PyThreadKiller(target=example_target)
thread.start()
# Allow the thread to run for 3 seconds
time.sleep(3)
# Kill the thread
result = thread.kill()
print(f"Return value after killing the thread: {result}")
# Output:
# Thread is running... 0
# Thread is running... 1
# Thread is running... 2
# Thread killed successfully
# Return value after killing the thread: None
This file: tests/UnittestPyThreadKiller.py
is integral to our CI/CD
pipeline for automated testing.
-
This project is licensed under the MIT License - see the LICENSE file for details.
-
This updated
README.md
includes the new project name, badges, a brief overview, the directory structure, installation instructions, usage example, changelog, and the main code for thePyThreadKiller
class. Make sure to adjust any URLs and links to point to the correct resources for your project.