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 collapsing-thread-pool-executor-py2
$ pip install .
$ pip install -r requirements.txt

# mkvirtualenv 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-2018.1.tar.gz.

File metadata

File hashes

Hashes for collapsing-thread-pool-executor-2018.1.tar.gz
Algorithm Hash digest
SHA256 34f99ba97c6b71ce196289b841871d9c6e3efd428f05136baa42ccb79a6e2040
MD5 ffa9487d18e0416e827ffab4b4163245
BLAKE2b-256 2e73fab3b6e06529ffb3633f719c4d4851b6592e21a60b801f5fc798dcfee4f3

See more details on using hashes here.

Provenance

File details

Details for the file collapsing_thread_pool_executor-2018.1-py3-none-any.whl.

File metadata

File hashes

Hashes for collapsing_thread_pool_executor-2018.1-py3-none-any.whl
Algorithm Hash digest
SHA256 243c9e20364dd3655787a1ee3c62ebb7863c37e0274dd8bdafa964e9f87f8d25
MD5 974ef99d663b37884ecbe4dc66d18f66
BLAKE2b-256 f9d44e4f9ffb8008c2be3ae425b90167ab25c988f4082886a60e9d5e9b650c65

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