threado
Project description
Threado
A simple way to run multiple threads do the I/O
Example
import string
from threado.simple_thread_runner import SimpleThreadsRunner
actions = list(string.ascii_lowercase)
sr = SimpleThreadsRunner()
sr.run_threads(5, lambda x:print("Thread output char:"+x), iter_data=actions)
# In case the iter_data : Iterator[Any] is an Iterator of large amounts data
sr.run_threads(5, lambda x:print("Thread output char:"+x), iter_data=actions, batch_size=20)
# Or it can be used separate as producer/consumer
thread_count = 3
for _ in actions:
sr.q_producer(_)
sr.q_consumer(thread_count, lambda x:print("Thread output char:"+x))
# File download
import urllib.request
url_list = [
'https://www.blog.pythonlibrary.org/wp-content/uploads/2012/06/dnd_text-150x93.png',
'https://www.blog.pythonlibrary.org/wp-content/uploads/2012/06/dnd_file-150x93.png',
'https://www.blog.pythonlibrary.org/wp-content/uploads/2012/06/panel_smack1-150x91.png'
]
def download_url(url: str):
pic_name = url.split("/")[-1:][0]
urllib.request.urlretrieve(url, pic_name)
sr = SimpleThreadsRunner()
sr.run_threads(3, download_url,iter_data=url_list)
# Simple load test
import time
def simple_loadTest(_thread_count, func, load_test_data):
s = SimpleThreadsRunner()
index = 0
for index, data in enumerate(load_test_data, start=1):
sr.q_producer(data)
_start = time.time()
s.q_consumer(func,_thread_count)
_end = time.time()
print(f"Total transitions: {index} \nTPS={index / (_end - _start)}")
Installing threado and Supported Versions
threado is available on PyPI:
$ python -m pip install threado
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
threado-1.6.tar.gz
(4.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
threado-1.6-py3-none-any.whl
(5.0 kB
view details)
File details
Details for the file threado-1.6.tar.gz.
File metadata
- Download URL: threado-1.6.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c14768aa6fd76620b06b58a086e93daf73084ebacf2805b6e40215c2eb16d1cb
|
|
| MD5 |
59f182e15955de9e9c23952b742cd744
|
|
| BLAKE2b-256 |
0170eb3f97bfa530243baddf32db29a2e53af9b4f79c8967e17dbdb045127989
|
File details
Details for the file threado-1.6-py3-none-any.whl.
File metadata
- Download URL: threado-1.6-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8078e271f4de13b19d3e2a3f5a6f687f6b22cf71b1195cdca5d6bada6a935de4
|
|
| MD5 |
451ae360da01dba36b9b3feb4a0aa0eb
|
|
| BLAKE2b-256 |
86a706da694a1dc69a5f30ed9fcfbab18c116f5c0062a3a3f09690155da7a3bc
|