Python Threadit
Running functions in threads with no effort
A nice package to help you run functions in threads and get their result.
This is under development! So please check for changes before updating
Installation
pip install threadit
Usage
import time
from threadit import ThreadIT
def get_company_name():
# Do work in thread
time.sleep(5)
return 'Adapted'
def do_some_work():
get_name = ThreadIT(get_company_name)
# do stuff or run a while loop to wait for result
more_thread = ThreadIT(get_company_name)
while get_name.doing_work():
print('Waiting for thread to finnish')
# You can also call .result() and the main thread will wait
# for the thread to return your result.
company_name = get_name.result()
# this will timeout the thread in 1 second if its not finished
company_name2 = more_thread.result(timeout=1)
print(company_name) # Outputs -> Adapted
print(company_name2) # Outputs -> None
Main commands
# Import the module
from threadit import ThreadIT
# Start your function with or without arguments
var = ThreadIT(function, args, kwargs)
# Wait for the function to finnish or get the result if its finished
var.result()
Optional commands
# Check if your thread is still working on the function.
# This will return True if the function is not completed.
var.doing_work()
# Terminate the thread. This will noe wait for the function to
# finnish and will return None as result if the function is not
# done within the timelimit set
var.result(timeout=10)
Testing
Use the following command to run tests.
python -m unittest threadit.tests.test_threadit
Changelog:
See CHANGELOG.md
Metadata
Release files for threadit 1.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 | Provenance | Actions |
|---|---|---|---|---|
| threadit-1.2.3.tar.gz | 3.2 kB | Without provenance | Details for threadit-1.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| threadit-1.2.3-py3-none-any.whl | Python 3 | none | any | Details for threadit-1.2.3-py3-none-any.whl |
Total release size: 7.0 kB
Release files / threadit-1.2.3.tar.gz
| Download URL | threadit-1.2.3.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4308591bd469ed03b26ccbca0dcccb62c8996a9b9305a0e25ef10f4cc055e002
|
|
BLAKE2b-256 checksum How to use checksums |
90a06092ee099d013a205614ff0e8d8875d64e8193b2ce284ea289e12d0e69c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Release files / threadit-1.2.3-py3-none-any.whl
| Download URL | threadit-1.2.3-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f27eb8dc51fcf9868173e0470af7d55408035763151d3e377a2363f9262f2655
|
|
BLAKE2b-256 checksum How to use checksums |
92635a6356cd9404be0be8a4dca75626b7985ddac299402cfe92ca76a54bcdc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Security for threadit 1.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.