Skip to main content

Library for running tasks in bounded pool executors.

Project description

bounded_pool

PyPI version FOSSA Status

Simplistic and universal bounded pool executor that allows to process N tasks as the same time while limiting size of the queue. Tasks can be functions or coroutines. Under the hood bounded_pool uses threads or processes, depending on used class. Refer to tests/test_basic.py for details.

Tasks will only be submited when there are available workers (specified by max_workers). You can specify max_queue_size to allow submiting more tasks than amount of available workers (so workers won't have to wait for task creation). Refer to tests/test_queue.py for details.

Exceptions inside of the tasks craeted with executors are ignored. Refer to tests/test_exceptions.py for details.

Example / Showcase

import time
from bounded_pool import BoundedThreadPoolExecutor


def test_example():
    futures = []

    with BoundedThreadPoolExecutor() as pool:
        for _ in range(64):
            future = pool.submit(time.sleep, 1)
            futures.append(future)

    assert futures

    for future in futures:
        assert future.done()
        assert future.result() is None

License

FOSSA Status

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

bounded_pool-0.0.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

bounded_pool-0.0.2-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

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