Skip to main content

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-0.1.4.tar.gz (2.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page