Skip to main content

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(5, lambda x:print("Thread output char:"+x))
sr.run_threads(iter_data=actions)

# In case the iter_data : Iterator[Any] is an Iterator of large amounts data

sr.run_threads(iter_data=actions, batch_size=20)

# Or it can be used separate as producer/consumer
for _ in actions:
    sr.q_producer(_)
    sr.q_consumer()

# File download
import urllib

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(3, download_url)
sr.run_threads(iter_data=url_list)

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

Uploaded Source

Built Distribution

threado-1.4-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

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