Skip to main content

A minimal Python 2+ thread pool designed for clarity, without reliance on `concurrent.futures`.

Project description

minimal-thread-pool

A minimal Python 2+ thread pool designed for clarity, without reliance on concurrent.futures.

Features

  • Explicit: If any submitted job raises an exception, the corresponding worker thread terminates loudly.
  • Easy lifecycle: Add tasks, then call .join() to wait for completion. Pull results as soon as they are ready.

Installation

pip install minimal-thread-pool

Usage

from __future__ import print_function
import time
import random
from minimal_thread_pool import MinimalThreadPool


def slow_square(x):
    time.sleep(random.randint(1, 10))
    return x * x


pool = MinimalThreadPool(num_threads=2)
for i in range(10):
    # def add_task(self, func, *args, **kwargs)
    pool.add_task(slow_square, i)

# Retrieve results (order not guaranteed)
for thread_index, result in pool.results():
    print('Worker %d returned %s' % (thread_index, result))

# Wait for all tasks
pool.join()

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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

minimal_thread_pool-0.1.0a0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minimal_thread_pool-0.1.0a0-py2.py3-none-any.whl (3.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file minimal_thread_pool-0.1.0a0.tar.gz.

File metadata

  • Download URL: minimal_thread_pool-0.1.0a0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for minimal_thread_pool-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 ee86008cce1d9c01a09c7f47c829cab1849600d8fd14da095c0ece15da729c96
MD5 9dab8a4bc36ae4033652fef085028b06
BLAKE2b-256 522174c8d193699f6c6d8317d78c7018f17b633cea74ae70c234ce3622df5e36

See more details on using hashes here.

File details

Details for the file minimal_thread_pool-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for minimal_thread_pool-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dbd16608caf93d4a742b94c2080895848fda7bad144da5a11f4223311bdbcf55
MD5 9dffcb556a99d875da33c2584451247c
BLAKE2b-256 31d12bc9e8a9d0f0502b3df41e4596387ceaf94614df8392a6770717d1ede4c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page