A simple threadpool
Project description
Intro
simple_threadpool: a simple 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
# 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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file simple_threadpool-1.0.0.tar.gz
.
File metadata
- Download URL: simple_threadpool-1.0.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce45ef35b9f484063a1b154c54adbc2fae64d6cf7c0bbed944da698414925d23 |
|
MD5 | bff9d3a36c5039b331e5b6ce8e0c1b3a |
|
BLAKE2b-256 | 0aae017b7958c9eda5e4bf1200f360eea3d50c7d239e8a800164b82ee2c12950 |
File details
Details for the file simple_threadpool-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: simple_threadpool-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 2.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 462f7ede783e05eed76959cb119bc4bfdd56c086bb5f4a6f9248bfc9672a5bea |
|
MD5 | 2410e2d8ac487b293aeb8c36f78e53b5 |
|
BLAKE2b-256 | 1297d2ef5075d982e67e552f0e9c66a1f41c6997d16b5a09958665c9f0ce685a |