Skip to main content

A thread pool that auto-manages the number of worker threads and is compatible with the "futures" module ThreadPoolExecutor interface.

Project description

CollapsingThreadPoolExecutor

The CollapsingThreadPoolExecutor is inspired by and compatible with the ThreadPoolExecutor from the "futures" module, it operates differently in that worker threads are handled with a stack which results in the same worker or workers doing all the work (and idle workers being destroyed).

How to install

$ pip install collapsing-thread-pool-executor

How to develop

Prerequisites

  • python3 w/ pip
  • python2 w/ pip
  • virtualenvwrapper
  • entr

Set up the environments

$ mkvirtualenv -p `which python2.7` collapsing-thread-pool-executor-py2
$ pip install .
$ pip install -r requirements.txt

$ mkvirtualenv -p `which python3` collapsing-thread-pool-executor-py3
$ pip install .
$ pip install -r requirements.txt

Watch the tests

# watch python2 tests in one window
$ workon collapsing-thread-pool-executor-py2
$ find ./ -name '*.py' | entr -c py.test -v --log-level=DEBUG collapsing_thread_pool_executor

# watch python3 tests in one window
$ workon collapsing-thread-pool-executor-py3
$ find ./ -name '*.py' | entr -c py.test -v --log-level=DEBUG collapsing_thread_pool_executor

Examples

The example below will execute some_task() 100 times; as some_task() should take a second to execute and as we've allocated 10 workers, the whole thing should take about 10 seconds.

import time

from collapsing_thread_pool_executor import CollapsingThreadPoolExecutor

def some_task():
    time.sleep(1)

# all arguments are optional
pool = CollapsingThreadPoolExecutor(
    workers=10,
    thread_name_prefix='SomePool',
    permitted_thread_age_in_seconds=60,
)

for i in range(0, 100):
    pool.submit(some_task)

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

Built Distribution

File details

Details for the file collapsing-thread-pool-executor-2019.10.tar.gz.

File metadata

  • Download URL: collapsing-thread-pool-executor-2019.10.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15

File hashes

Hashes for collapsing-thread-pool-executor-2019.10.tar.gz
Algorithm Hash digest
SHA256 02a3087372067f3fa6dd26b49239ed45f088fd57edfb1e4abb8d35385d12451e
MD5 bb812de88fe21767508870d7139dadff
BLAKE2b-256 1c2a93f3b44ceb5408e0fed1b476973266a51cdab6ad54ebc113403b50f74531

See more details on using hashes here.

Provenance

File details

Details for the file collapsing_thread_pool_executor-2019.10-py2-none-any.whl.

File metadata

  • Download URL: collapsing_thread_pool_executor-2019.10-py2-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15

File hashes

Hashes for collapsing_thread_pool_executor-2019.10-py2-none-any.whl
Algorithm Hash digest
SHA256 c0452b7491bea45d91dcc5534742148479931b9bd3695fae29b0eb9228ffe6e9
MD5 9fce439041fc44c3f154840d74fac4f9
BLAKE2b-256 dbe5ab3f932bb631e50fe4f4688d79fd217b9db6eb107092bb747e6059977791

See more details on using hashes here.

Provenance

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