Use threads with return values
Project description
# threadedreturn
`threadedreturn` is a Python package that provides a simple extension to the built-in `Thread` class in the `threading` module. The `ThreadWithReturnValue` class in this package allows you to create threads with return values.
## Installation
You can install `threadedreturn` using `pip`:
```bash
pip install threadedreturn
```
## Usage
### ThreadWithReturnValue
`ThreadWithReturnValue` is a subclass of `Thread` that enables you to retrieve the return value of a function or method running in a separate thread.
#### Example
```python
from threadedreturn import ThreadWithReturnValue
# Define a function to be executed in a separate thread
def my_function(arg1, arg2):
# Some time-consuming task
result = arg1 + arg2
return result
# Create a ThreadWithReturnValue instance
thread = ThreadWithReturnValue(target=my_function, args=(3, 5))
# Start the thread
thread.start()
# Wait for the thread to finish and retrieve the return value
result = thread.join()
print("Result:", result)
```
## Contributing
If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/DWAA1660/threadedreturn).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
threadedreturn-1.0.1.tar.gz
(2.0 kB
view details)
File details
Details for the file threadedreturn-1.0.1.tar.gz
.
File metadata
- Download URL: threadedreturn-1.0.1.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18abf8d72df2043f49a678c4a0e35c7e5b506bd64723f2d89fa500ccd53a475d |
|
MD5 | b453d00d8aae8e8802ce2744f7ed9051 |
|
BLAKE2b-256 | 3eeacd7dd04959b22790c38baf559cba1640c1596938d9acf7261c92fb3f0f94 |