Skip to main content

simple_threadpool

A simple threadpool, supports large iterable job queue(add on demand, compared to concurrent.futures.ThreadPoolExecutor and multiprocessing.pool.ThreadPool).

Install

pip install simple_threadpool

Usage

from __future__ import print_function

import random, time
from threading import current_thread
from simple_threadpool import ThreadPool


def my_worker(arg):
    '''
    custom worker
    '''
    print('%s: ' % current_thread().name, arg + 1)
    time.sleep(random.random())


def large_iterable(size):
    for i in range(size):
        print('getting %s' % i)
        yield i


def callback(result):
    print(result)


# create a ThreadPool instance with 2 threads
tp = ThreadPool(my_worker, max_workers=2)
print('max_workers: %d' % tp.max_workers)
print('chunksize: %d' % tp.queue.maxsize)

# produce and send some data to the pool
print('First round:')
tp.feed([1, 2, 3, 4, 5])

print('Second round:')
tp.feed([6, 7, 8, 9, 0])

print('Large jobs:')
tp.feed(large_iterable(15))
# close the queue
tp.close()

print('Using callback (callback function will be threadsafe)')
tp = ThreadPool(my_worker, result_callback=callback)
tp.feed([1, 2, 3])
tp.close()

Metadata

Release files for simple-threadpool 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-threadpool 1.0.1
File Size Uploaded Provenance
simple_threadpool-1.0.1.tar.gz 3.9 kB Without provenance Details

Release files / simple_threadpool-1.0.1.tar.gz

Download URL simple_threadpool-1.0.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
86f9343cfc25b59c7e89558d9f59fe98bc0d1774aa32af1fd493c78677b2a964
BLAKE2b-256 checksum
How to use checksums
a43ed2ddbc22e8b5a463a82ee9bd8138e42f357c43ccd68695eb8d1395df650f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Security for simple-threadpool 1.0.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page