noxdafox/pebble

Multi threading and processing eye-candy.

Python

656

650 commits

updated Oct 10, 2026

See the code

README

Pebble
======

Pebble provides a neat API to manage threads and processes within an application.

:Source: https://github.com/noxdafox/pebble
:Documentation: https://pebble.readthedocs.io
:Download: https://pypi.org/project/Pebble/

|build badge| |docs badge| |downloads badge|

.. |build badge| image:: https://github.com/noxdafox/pebble/actions/workflows/tests.yml/badge.svg
   :target: https://github.com/noxdafox/pebble/actions/workflows/tests.yml
   :alt: Build Status
.. |docs badge| image:: https://readthedocs.org/projects/pebble/badge/?version=latest
   :target: https://pebble.readthedocs.io
   :alt: Documentation Status
.. |downloads badge| image:: https://img.shields.io/pypi/dm/pebble
   :target: https://pypistats.org/packages/pebble
   :alt: PyPI - Downloads

Examples
--------

Run a job in a separate thread and wait for its results.

.. code:: python

    from pebble import concurrent

    @concurrent.thread
    def function(foo, bar=0):
        return foo + bar

    future = function(1, bar=2)

    result = future.result()  # blocks until results are ready

Same code with AsyncIO support.

.. code:: python

    import asyncio

    from pebble import asynchronous

    @asynchronous.thread
    def function(foo, bar=0):
        return foo + bar

    async def asynchronous_function():
        result = await function(1, bar=2)  # blocks until results are ready
        print(result)

    asyncio.run(asynchronous_function())

Run a function with a timeout of ten seconds and deal with errors.

.. code:: python

    from pebble import concurrent
    from concurrent.futures import TimeoutError

    @concurrent.process(timeout=10)
    def function(foo, bar=0):
        return foo + bar

    future = function(1, bar=2)

    try:
        result = future.result()  # blocks until results are ready
    except TimeoutError as error:
        print("Function took longer than %d seconds" % error.args[1])
    except Exception as error:
        print("Function raised %s" % error)
        print(error.traceback)  # traceback of the function

Pools support workers restart, timeout for long running tasks and more.

.. code:: python

    from pebble import ProcessPool
    from concurrent.futures import TimeoutError

    TIMEOUT_SECONDS = 3

    def function(foo, bar=0):
        return foo + bar

    def task_done(future):
        try:
            result = future.result()  # blocks until results are ready
        except TimeoutError as error:
            print("Function took longer than %d seconds" % error.args[1])
        except Exception as error:
            print("Function raised %s" % error)
            print(error.traceback)  # traceback of the function

    with ProcessPool(max_workers=5, max_tasks=10) as pool:
        for index in range(0, 10):
            future = pool.schedule(function, index, bar=1, timeout=TIMEOUT_SECONDS)
            future.add_done_callback(task_done)

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

asyncio
decorators
multiprocessing
pool
python
threading

noxdafox/pebble

Multi threading and processing eye-candy.

Python

656

650 commits

updated Oct 10, 2026

See the code

README

Pebble
======

Pebble provides a neat API to manage threads and processes within an application.

:Source: https://github.com/noxdafox/pebble
:Documentation: https://pebble.readthedocs.io
:Download: https://pypi.org/project/Pebble/

|build badge| |docs badge| |downloads badge|

.. |build badge| image:: https://github.com/noxdafox/pebble/actions/workflows/tests.yml/badge.svg
   :target: https://github.com/noxdafox/pebble/actions/workflows/tests.yml
   :alt: Build Status
.. |docs badge| image:: https://readthedocs.org/projects/pebble/badge/?version=latest
   :target: https://pebble.readthedocs.io
   :alt: Documentation Status
.. |downloads badge| image:: https://img.shields.io/pypi/dm/pebble
   :target: https://pypistats.org/packages/pebble
   :alt: PyPI - Downloads

Examples
--------

Run a job in a separate thread and wait for its results.

.. code:: python

    from pebble import concurrent

    @concurrent.thread
    def function(foo, bar=0):
        return foo + bar

    future = function(1, bar=2)

    result = future.result()  # blocks until results are ready

Same code with AsyncIO support.

.. code:: python

    import asyncio

    from pebble import asynchronous

    @asynchronous.thread
    def function(foo, bar=0):
        return foo + bar

    async def asynchronous_function():
        result = await function(1, bar=2)  # blocks until results are ready
        print(result)

    asyncio.run(asynchronous_function())

Run a function with a timeout of ten seconds and deal with errors.

.. code:: python

    from pebble import concurrent
    from concurrent.futures import TimeoutError

    @concurrent.process(timeout=10)
    def function(foo, bar=0):
        return foo + bar

    future = function(1, bar=2)

    try:
        result = future.result()  # blocks until results are ready
    except TimeoutError as error:
        print("Function took longer than %d seconds" % error.args[1])
    except Exception as error:
        print("Function raised %s" % error)
        print(error.traceback)  # traceback of the function

Pools support workers restart, timeout for long running tasks and more.

.. code:: python

    from pebble import ProcessPool
    from concurrent.futures import TimeoutError

    TIMEOUT_SECONDS = 3

    def function(foo, bar=0):
        return foo + bar

    def task_done(future):
        try:
            result = future.result()  # blocks until results are ready
        except TimeoutError as error:
            print("Function took longer than %d seconds" % error.args[1])
        except Exception as error:
            print("Function raised %s" % error)
            print(error.traceback)  # traceback of the function

    with ProcessPool(max_workers=5, max_tasks=10) as pool:
        for index in range(0, 10):
            future = pool.schedule(function, index, bar=1, timeout=TIMEOUT_SECONDS)
            future.add_done_callback(task_done)

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

asyncio
decorators
multiprocessing
pool
python
threading

Project health

Overall

3.9/10

Maintained

10/10

Code review

1/10
OpenSSF Scorecard

PyPI

Latest release

5.2.3 · Oct 4, 2026

Releases this year

4

Significant stargazers

Jonas Haag

424 followers · starred Oct 2023

Jiawei Liu

692 followers · starred May 2023

Kevin Ko

941 followers · starred Jan 2023

Zxilly

219 followers · starred Nov 2025