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)
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
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
Close
Hashes for collapsing-thread-pool-executor-2018.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e1adce9116eab1229844cb459bc6a421649290dda31fdfb67bae899eda0f5a |
|
MD5 | dc4a29feba1aa8273b1ac9491c4b654b |
|
BLAKE2b-256 | 84eb2944e2d902d6dbd1a9216e51c9d41241ce74842fbf5053e1f403386e1fe4 |
Close
Hashes for collapsing_thread_pool_executor-2018.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57b6ea9e179552c7fc618718631fe8f43441d7b929abbe44422348b1dec23ee1 |
|
MD5 | e87e4acb8d11f0057ec187454a2e1350 |
|
BLAKE2b-256 | 4764fdaeff0dd805ba753d4f10345bf8a2c889b9971a1a200ec8b5cc69d67f6b |