retryloop


Nameretryloop JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/retryloop
Summaryallows you to execute a given function on each element of an iterable, with the ability to retry failed attempts a specified number of times
upload_time2023-07-08 00:01:31
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords retry loop
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# allows you to execute a given function on each element of an iterable, with the ability to retry failed attempts a specified number of times

## pip install retryloop 

The retryloop function is a utility function that allows you to execute a given function 
on each element of an iterable, with the ability to retry failed attempts a specified number of times. 
It provides error resilience and flexibility in handling exceptions during function execution.


### Error Resilience: 

The function allows you to retry the execution of a given function on a collection 
of elements, providing resilience in the face of potential errors or exceptions. 
It retries failed attempts a specified number of times (maxretries), which can be 
helpful when dealing with intermittent errors or unreliable external resources.

### Customizable Retry Behavior: 

You can control the number of retries (maxretries) for each failed attempt. This 
flexibility enables you to fine-tune the retry behavior based on the specific 
requirements of your application.

### Input and Result Tracking:

By setting add_input to True, the function keeps track of the input elements along 
with their corresponding results. This can be valuable for debugging purposes or for 
analyzing the behavior of the function on different inputs.

### Result Collection: 

If results is set to True, the function collects and returns the results in a list. 
This simplifies the process of aggregating and processing the outcomes of the function executions.


## Example Usage

```python
from retryloop import retryloop
from random import randint
def devidefunction(no, multi, plus):
    return 10 / no * multi + plus
i = [randint(0, 2) for _ in range(10)] # [2, 2, 1, 2, 2, 0, 2, 2, 1, 1]
results = retryloop(devidefunction, i, args=(5,), kwargs={'plus': 10}, maxretries=3, verbose=True)
print(results)
counter: 1
division by zero
counter: 2
division by zero
counter: 3
division by zero
[[0, 2, 35.0],
 [1, 2, 35.0],
 [2, 1, 60.0],
 [3, 2, 35.0],
 [4, 2, 35.0],
 [6, 2, 35.0],
 [7, 2, 35.0],
 [8, 1, 60.0],
 [9, 1, 60.0]]
 
##############################
 
from retryloop import retryloop
from random import randint
def devidefunction(no, multi, plus):
    return 10 / no * multi + plus
i = [randint(0, 2) for _ in range(10)] # [2, 1, 2, 2, 2, 2, 2, 2, 2, 0]
results = retryloop(devidefunction, i, args=(5,), kwargs={'plus': 10}, maxretries=3, verbose=True, add_input=False, results=True)
print(results)
counter: 1
division by zero
counter: 2
division by zero
counter: 3
division by zero
[[0, 35.0], [1, 60.0], [2, 35.0], [3, 35.0], [4, 35.0], [5, 35.0], [6, 35.0], [7, 35.0], [8, 35.0]]




retryloop(
    f,
    i: list,
    args: tuple = (),
    kwargs: dict | None = None,
    maxretries: int = 5,
    add_input: bool = True,
    results: bool = True,
    verbose: bool = True,
):
    """
    Execute the given function on each element of the iterable, retrying failed attempts a specified number of times.

    Args:
        f (callable): The function to be executed on each element of the iterable.
        i (list): The iterable containing the elements on which the function is applied.
        args (tuple, optional): The positional arguments to be passed to the function `f`. Defaults to ().
        kwargs (dict, optional): The keyword arguments to be passed to the function `f`. Defaults to None.
        maxretries (int, optional): The maximum number of retries for each failed attempt. Defaults to 5.
        add_input (bool, optional): Whether to include the input element along with the result in the results list.
                                   Defaults to True.
        results (bool, optional): Whether to collect and return the results in a list. Defaults to True.
        verbose (bool, optional): Whether to print error messages and retry counter. Defaults to True.

    Returns:
        list: A list of results, where each result is a list [index, input_element, function_result] if `add_input` is True,
              or [index, function_result] if `add_input` is False. If `results` is False, an empty list is returned.
    """
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/retryloop",
    "name": "retryloop",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "retry,loop",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bf/d5/3c405dc959fb6a47f3f514c0bd87671a778f6f570d92692887c74d2e5eaf/retryloop-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# allows you to execute a given function on each element of an iterable, with the ability to retry failed attempts a specified number of times\r\n\r\n## pip install retryloop \r\n\r\nThe retryloop function is a utility function that allows you to execute a given function \r\non each element of an iterable, with the ability to retry failed attempts a specified number of times. \r\nIt provides error resilience and flexibility in handling exceptions during function execution.\r\n\r\n\r\n### Error Resilience: \r\n\r\nThe function allows you to retry the execution of a given function on a collection \r\nof elements, providing resilience in the face of potential errors or exceptions. \r\nIt retries failed attempts a specified number of times (maxretries), which can be \r\nhelpful when dealing with intermittent errors or unreliable external resources.\r\n\r\n### Customizable Retry Behavior: \r\n\r\nYou can control the number of retries (maxretries) for each failed attempt. This \r\nflexibility enables you to fine-tune the retry behavior based on the specific \r\nrequirements of your application.\r\n\r\n### Input and Result Tracking:\r\n\r\nBy setting add_input to True, the function keeps track of the input elements along \r\nwith their corresponding results. This can be valuable for debugging purposes or for \r\nanalyzing the behavior of the function on different inputs.\r\n\r\n### Result Collection: \r\n\r\nIf results is set to True, the function collects and returns the results in a list. \r\nThis simplifies the process of aggregating and processing the outcomes of the function executions.\r\n\r\n\r\n## Example Usage\r\n\r\n```python\r\nfrom retryloop import retryloop\r\nfrom random import randint\r\ndef devidefunction(no, multi, plus):\r\n    return 10 / no * multi + plus\r\ni = [randint(0, 2) for _ in range(10)] # [2, 2, 1, 2, 2, 0, 2, 2, 1, 1]\r\nresults = retryloop(devidefunction, i, args=(5,), kwargs={'plus': 10}, maxretries=3, verbose=True)\r\nprint(results)\r\ncounter: 1\r\ndivision by zero\r\ncounter: 2\r\ndivision by zero\r\ncounter: 3\r\ndivision by zero\r\n[[0, 2, 35.0],\r\n [1, 2, 35.0],\r\n [2, 1, 60.0],\r\n [3, 2, 35.0],\r\n [4, 2, 35.0],\r\n [6, 2, 35.0],\r\n [7, 2, 35.0],\r\n [8, 1, 60.0],\r\n [9, 1, 60.0]]\r\n \r\n##############################\r\n \r\nfrom retryloop import retryloop\r\nfrom random import randint\r\ndef devidefunction(no, multi, plus):\r\n    return 10 / no * multi + plus\r\ni = [randint(0, 2) for _ in range(10)] # [2, 1, 2, 2, 2, 2, 2, 2, 2, 0]\r\nresults = retryloop(devidefunction, i, args=(5,), kwargs={'plus': 10}, maxretries=3, verbose=True, add_input=False, results=True)\r\nprint(results)\r\ncounter: 1\r\ndivision by zero\r\ncounter: 2\r\ndivision by zero\r\ncounter: 3\r\ndivision by zero\r\n[[0, 35.0], [1, 60.0], [2, 35.0], [3, 35.0], [4, 35.0], [5, 35.0], [6, 35.0], [7, 35.0], [8, 35.0]]\r\n\r\n\r\n\r\n\r\nretryloop(\r\n    f,\r\n    i: list,\r\n    args: tuple = (),\r\n    kwargs: dict | None = None,\r\n    maxretries: int = 5,\r\n    add_input: bool = True,\r\n    results: bool = True,\r\n    verbose: bool = True,\r\n):\r\n    \"\"\"\r\n    Execute the given function on each element of the iterable, retrying failed attempts a specified number of times.\r\n\r\n    Args:\r\n        f (callable): The function to be executed on each element of the iterable.\r\n        i (list): The iterable containing the elements on which the function is applied.\r\n        args (tuple, optional): The positional arguments to be passed to the function `f`. Defaults to ().\r\n        kwargs (dict, optional): The keyword arguments to be passed to the function `f`. Defaults to None.\r\n        maxretries (int, optional): The maximum number of retries for each failed attempt. Defaults to 5.\r\n        add_input (bool, optional): Whether to include the input element along with the result in the results list.\r\n                                   Defaults to True.\r\n        results (bool, optional): Whether to collect and return the results in a list. Defaults to True.\r\n        verbose (bool, optional): Whether to print error messages and retry counter. Defaults to True.\r\n\r\n    Returns:\r\n        list: A list of results, where each result is a list [index, input_element, function_result] if `add_input` is True,\r\n              or [index, function_result] if `add_input` is False. If `results` is False, an empty list is returned.\r\n    \"\"\"\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "allows you to execute a given function on each element of an iterable, with the ability to retry failed attempts a specified number of times",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/retryloop"
    },
    "split_keywords": [
        "retry",
        "loop"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe8b72a64a1a30dd7a6e72a18e7f7aa30df7a874c47c240bcc24ae49e59d4b87",
                "md5": "c598fd252a05a7d08c18880bb8ff444d",
                "sha256": "8a84c460f129b950254ea1d21eed540532c49d1aa1043ca7e077210cadd732ce"
            },
            "downloads": -1,
            "filename": "retryloop-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c598fd252a05a7d08c18880bb8ff444d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6411,
            "upload_time": "2023-07-08T00:01:29",
            "upload_time_iso_8601": "2023-07-08T00:01:29.737303Z",
            "url": "https://files.pythonhosted.org/packages/fe/8b/72a64a1a30dd7a6e72a18e7f7aa30df7a874c47c240bcc24ae49e59d4b87/retryloop-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bfd53c405dc959fb6a47f3f514c0bd87671a778f6f570d92692887c74d2e5eaf",
                "md5": "bad24d251e441d1cea8fff7badeeca51",
                "sha256": "492993c291c2867c158fdf86f10f3e2228dd23cfe549de8356120d0c024a962d"
            },
            "downloads": -1,
            "filename": "retryloop-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "bad24d251e441d1cea8fff7badeeca51",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4325,
            "upload_time": "2023-07-08T00:01:31",
            "upload_time_iso_8601": "2023-07-08T00:01:31.464240Z",
            "url": "https://files.pythonhosted.org/packages/bf/d5/3c405dc959fb6a47f3f514c0bd87671a778f6f570d92692887c74d2e5eaf/retryloop-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-08 00:01:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "retryloop",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "retryloop"
}
        
Elapsed time: 0.12896s