Skip to main content

Threads, but with more features!

Project description

PyBetterThreads

Downloads PyPi License

PyBetterThreads is a Python library for adding more features to the threading module in Python.

PyBetterThreads makes it possible to return values from threads, and adds a finished signal so that the user can execute a function once the thread is finished. It is still in early development, and more features will be added soon.

Installation

You can install PyBetterThreads using pip:

pip install PyBetterThreads

Usage

Here is an example of how to use PyBetterThreads:

from PyBetterThreads import BetterThread
from time import sleep

def my_function():
    sleep(5)
    return "Hello, World!"

thread = BetterThread(target=my_function)
thread.start()
thread.connect(print)

The above code will print "Hello, World!" after 5 seconds, as once the thread is finished, the returned value will passed to the print function. The returned value of the thread will be stored in the value attribute of the thread.

You can also use the join method to wait for the thread to finish and get the returned value, instead of connecting a function to the thread:

from PyBetterThreads import BetterThread
from time import sleep

def my_function():
    sleep(5)
    return "Hello, World!"

thread = BetterThread(target=my_function)
thread.start()
thread.join()
print(f"The thread returned: {thread.value}")

The above code will print "Hello, World!" after 5 seconds, as once the thread is finished, the returned value will be stored in the value attribute of the thread.

Features

  • Return values from threads
  • Execute a function once the thread is finished
  • More features coming soon!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Star History

Star History Chart

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

pybetterthreads-0.0.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

PyBetterThreads-0.0.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pybetterthreads-0.0.3.tar.gz.

File metadata

  • Download URL: pybetterthreads-0.0.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.1

File hashes

Hashes for pybetterthreads-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4ad65cd1bd4b1a2ea7ad4760df73d52b0caa433c9236eb092e0be14bc31d7fd3
MD5 c1e97750db698f54f2de7d6d13d37a02
BLAKE2b-256 5c2000d480fdd9bb9d341b03822c87f45b7c758db01b9f1790921f5bcb23ec18

See more details on using hashes here.

File details

Details for the file PyBetterThreads-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for PyBetterThreads-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 48bdb3c6c362cdf1f0493cfef4b62a4741fbc578f50266866f2ffffb412d51d8
MD5 fd3295483c1980ff3dd843c06a09ac6a
BLAKE2b-256 35e25311880c1b65e8f666c9207a24cc3a4e04711c52f6c1e79c294610c3b05a

See more details on using hashes here.

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