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/action.yml/badge.svg
:target: https://github.com/noxdafox/pebble/actions/workflows/action.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)
Raw data
{
"_id": null,
"home_page": "https://github.com/noxdafox/pebble",
"name": "Pebble",
"maintainer": null,
"docs_url": "https://pythonhosted.org/Pebble/",
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "thread process pool decorator",
"author": "Matteo Cafasso",
"author_email": "noxdafox@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5f/f2/41eda2cd73825d82143716776df0b7d9b8c6c6bf2d48ad86686098b4f73d/pebble-5.1.2.tar.gz",
"platform": null,
"description": "Pebble\n======\n\nPebble provides a neat API to manage threads and processes within an application.\n\n:Source: https://github.com/noxdafox/pebble\n:Documentation: https://pebble.readthedocs.io\n:Download: https://pypi.org/project/Pebble/\n\n|build badge| |docs badge| |downloads badge|\n\n.. |build badge| image:: https://github.com/noxdafox/pebble/actions/workflows/action.yml/badge.svg\n :target: https://github.com/noxdafox/pebble/actions/workflows/action.yml\n :alt: Build Status\n.. |docs badge| image:: https://readthedocs.org/projects/pebble/badge/?version=latest\n :target: https://pebble.readthedocs.io\n :alt: Documentation Status\n.. |downloads badge| image:: https://img.shields.io/pypi/dm/pebble\n :target: https://pypistats.org/packages/pebble\n :alt: PyPI - Downloads\n\nExamples\n--------\n\nRun a job in a separate thread and wait for its results.\n\n.. code:: python\n\n from pebble import concurrent\n\n @concurrent.thread\n def function(foo, bar=0):\n return foo + bar\n\n future = function(1, bar=2)\n\n result = future.result() # blocks until results are ready\n\nSame code with AsyncIO support.\n\n.. code:: python\n\n import asyncio\n\n from pebble import asynchronous\n\n @asynchronous.thread\n def function(foo, bar=0):\n return foo + bar\n\n async def asynchronous_function():\n result = await function(1, bar=2) # blocks until results are ready\n print(result)\n\n asyncio.run(asynchronous_function())\n\nRun a function with a timeout of ten seconds and deal with errors.\n\n.. code:: python\n\n from pebble import concurrent\n from concurrent.futures import TimeoutError\n\n @concurrent.process(timeout=10)\n def function(foo, bar=0):\n return foo + bar\n\n future = function(1, bar=2)\n\n try:\n result = future.result() # blocks until results are ready\n except TimeoutError as error:\n print(\"Function took longer than %d seconds\" % error.args[1])\n except Exception as error:\n print(\"Function raised %s\" % error)\n print(error.traceback) # traceback of the function\n\nPools support workers restart, timeout for long running tasks and more.\n\n.. code:: python\n\n from pebble import ProcessPool\n from concurrent.futures import TimeoutError\n\n TIMEOUT_SECONDS = 3\n\n def function(foo, bar=0):\n return foo + bar\n\n def task_done(future):\n try:\n result = future.result() # blocks until results are ready\n except TimeoutError as error:\n print(\"Function took longer than %d seconds\" % error.args[1])\n except Exception as error:\n print(\"Function raised %s\" % error)\n print(error.traceback) # traceback of the function\n\n with ProcessPool(max_workers=5, max_tasks=10) as pool:\n for index in range(0, 10):\n future = pool.schedule(function, index, bar=1, timeout=TIMEOUT_SECONDS)\n future.add_done_callback(task_done)\n",
"bugtrack_url": null,
"license": "LGPL",
"summary": "Threading and multiprocessing eye-candy.",
"version": "5.1.2",
"project_urls": {
"Homepage": "https://github.com/noxdafox/pebble"
},
"split_keywords": [
"thread",
"process",
"pool",
"decorator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "66f36f3c8426bbc9bf193d88c4d56a3ede6130709211b1e4bd9f022a6d35c91c",
"md5": "318fbd9578361ec645a1205f61ab19aa",
"sha256": "89bf53e31aab823cae323cb9c92667b4cba468fcc9d194804fdaf049d779a1f2"
},
"downloads": -1,
"filename": "Pebble-5.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "318fbd9578361ec645a1205f61ab19aa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 36864,
"upload_time": "2025-07-24T21:22:49",
"upload_time_iso_8601": "2025-07-24T21:22:49.352567Z",
"url": "https://files.pythonhosted.org/packages/66/f3/6f3c8426bbc9bf193d88c4d56a3ede6130709211b1e4bd9f022a6d35c91c/Pebble-5.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5ff241eda2cd73825d82143716776df0b7d9b8c6c6bf2d48ad86686098b4f73d",
"md5": "de764e9da7cd390b5a87fe8a99d1ff04",
"sha256": "9d1fb7c81ae9f9c6679558ac21289f9fa382826939fa80c8ef67f9b5e6a38a3f"
},
"downloads": -1,
"filename": "pebble-5.1.2.tar.gz",
"has_sig": false,
"md5_digest": "de764e9da7cd390b5a87fe8a99d1ff04",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 38813,
"upload_time": "2025-07-24T21:22:50",
"upload_time_iso_8601": "2025-07-24T21:22:50.999487Z",
"url": "https://files.pythonhosted.org/packages/5f/f2/41eda2cd73825d82143716776df0b7d9b8c6c6bf2d48ad86686098b4f73d/pebble-5.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 21:22:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "noxdafox",
"github_project": "pebble",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pebble"
}