Pebble


NamePebble JSON
Version 5.0.7 PyPI version JSON
download
home_pagehttps://github.com/noxdafox/pebble
SummaryThreading and multiprocessing eye-candy.
upload_time2024-03-21 22:34:46
maintainerNone
docs_urlhttps://pythonhosted.org/Pebble/
authorMatteo Cafasso
requires_python>=3.6
licenseLGPL
keywords thread process pool decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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.6",
    "maintainer_email": null,
    "keywords": "thread process pool decorator",
    "author": "Matteo Cafasso",
    "author_email": "noxdafox@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/34/9d/c7a0c8cfb32f532c63a4ef816b8bcf03d6e6ef63617713fb0953cfe7052c/Pebble-5.0.7.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.0.7",
    "project_urls": {
        "Homepage": "https://github.com/noxdafox/pebble"
    },
    "split_keywords": [
        "thread",
        "process",
        "pool",
        "decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da31ac6157816f5ed9440f3ad8744dc171f51ec59cc6c0b50c70d3c8a09add2f",
                "md5": "f72078299d381c37a73243d7d1dc90d6",
                "sha256": "f1742f2a62e8544e722c7b387211fb1a06038ca8cda322e5d55c84c793fd8d7d"
            },
            "downloads": -1,
            "filename": "Pebble-5.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f72078299d381c37a73243d7d1dc90d6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 30958,
            "upload_time": "2024-03-21T22:34:42",
            "upload_time_iso_8601": "2024-03-21T22:34:42.541097Z",
            "url": "https://files.pythonhosted.org/packages/da/31/ac6157816f5ed9440f3ad8744dc171f51ec59cc6c0b50c70d3c8a09add2f/Pebble-5.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "349dc7a0c8cfb32f532c63a4ef816b8bcf03d6e6ef63617713fb0953cfe7052c",
                "md5": "657ae3d58cc82124983048acd9ed9c89",
                "sha256": "2784c147766f06388cea784084b14bec93fdbaa793830f1983155aa330a2a6e4"
            },
            "downloads": -1,
            "filename": "Pebble-5.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "657ae3d58cc82124983048acd9ed9c89",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 32054,
            "upload_time": "2024-03-21T22:34:46",
            "upload_time_iso_8601": "2024-03-21T22:34:46.754592Z",
            "url": "https://files.pythonhosted.org/packages/34/9d/c7a0c8cfb32f532c63a4ef816b8bcf03d6e6ef63617713fb0953cfe7052c/Pebble-5.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-21 22:34:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "noxdafox",
    "github_project": "pebble",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pebble"
}
        
Elapsed time: 0.22759s