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/c6/b2/a83f1d951977e6392efdb21f4a901a3fd920b992450de9a464e59241d2ed/Pebble-5.1.0.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.0",
"project_urls": {
"Homepage": "https://github.com/noxdafox/pebble"
},
"split_keywords": [
"thread",
"process",
"pool",
"decorator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "31690fa75151350a9d7b848bfde929673ad505346940ae2713f862647394f0f7",
"md5": "34faf1d32a56719cdec1d6ee90c3759c",
"sha256": "530a398299ecd3a4ed1baf2e4b8045d8280b1e665560b0b409f8d8e58db60111"
},
"downloads": -1,
"filename": "Pebble-5.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "34faf1d32a56719cdec1d6ee90c3759c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 36177,
"upload_time": "2024-11-27T20:51:05",
"upload_time_iso_8601": "2024-11-27T20:51:05.829799Z",
"url": "https://files.pythonhosted.org/packages/31/69/0fa75151350a9d7b848bfde929673ad505346940ae2713f862647394f0f7/Pebble-5.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c6b2a83f1d951977e6392efdb21f4a901a3fd920b992450de9a464e59241d2ed",
"md5": "0978fc336a3b63c5eb4ef6d759b43d66",
"sha256": "5c30376f1827b21ecec4126ff90e7f22ad5501cac1ff2b32c86ff2601681f932"
},
"downloads": -1,
"filename": "Pebble-5.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0978fc336a3b63c5eb4ef6d759b43d66",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 35060,
"upload_time": "2024-11-27T20:51:07",
"upload_time_iso_8601": "2024-11-27T20:51:07.722316Z",
"url": "https://files.pythonhosted.org/packages/c6/b2/a83f1d951977e6392efdb21f4a901a3fd920b992450de9a464e59241d2ed/Pebble-5.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-27 20:51:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "noxdafox",
"github_project": "pebble",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pebble"
}