{ "info": { "author": "Todd Sifleet", "author_email": "todd.siflet@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "A python retry wrapper/decorator\n================================\n\n|PyPi Version|\n|Travis Test Status|\n\nA simple way to auto retry a funciton that has the possibility of\nraising an error. You can either call retry directly or decorate a\nfunction to get it to retry. Intelligent matching logic allows you to\nretry certain exception while raising other exceptions.\n\nCall a function directly:\n-------------------------\n\n::\n\n from retrypy import retry, check\n\n def dummy_func():\n print \"dummy_func called...\"\n raise Exception(\"House\")\n\n retry.call(\n dummy_func,\n times=2\n )\n\n dummy_func called...\n dummy_func called...\n Exception: House\n\n # usign a check method\n retry.call(\n dummy_func,\n check = check.message_equals(\"foobar\")\n )\n dummy_func called...\n Exception: House\n\nDecorating a function:\n----------------------\n\n::\n\n # Only retry IOErrors\n @retry.decorate(IOError, times=2)\n def dummy_func():\n print \"dummy_func called...\"\n raise IOError(\"House\")\n dummy_func()\n\n dummy_func called...\n dummy_func called...\n IOError: House\n\n # Retry any Exception, use a custom wait function\n @retry.decorate(times=2, wait=lambda n: 2*n)\n def dummy_func():\n print \"dummy_func called...\"\n raise Exception(\"House\")\n dummy_func()\n\n dummy_func called...\n dummy_func called...\n Exception: House\n\nWrap a function and return a new callable:\n------------------------------------------\n\n::\n\n def dummy_func():\n print \"dummy_func called...\"\n raise Exception(\"House\")\n\n func = retry.wrap(\n dummy_func,\n times=2\n )\n func()\n\n dummy_func called...\n dummy_func called...\n Exception: House\n\nDelay Helpers:\n--------------\n\nFunctions to implement some common backoff strategies: random, exponential, and incremental.\n\n**Random**::\n\n import time\n from retrypy import retry, delay\n\n def dummy_func():\n print time.time()\n raise Exception(\"House\")\n\n retry.call(dummy_func, wait=delay.random(\n min_seconds=1,\n max_seconds=5,\n ))\n\nOutput (wait times: .66s, .84s, 3.42s, .33s)::\n\n 1423297137.49\n 1423297138.15\n 1423297138.99\n 1423297142.41\n 1423297142.74\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"retrypy/retry.py\", line 63, in call\n wait,\n File \"retrypy/retry.py\", line 29, in _retry\n raise previous_exception\n Exception: House\n\n**Exponential**::\n\n import time\n from retrypy import retry, delay\n\n def dummy_func():\n print time.time()\n raise Exception(\"House\")\n\n retry.call(dummy_func, wait=delay.exponential(\n start_at=1,\n ))\n\nOutput (wait times: 1s, 2s, 4s, 8s)::\n\n 1423297238.49\n 1423297239.49\n 1423297241.49\n 1423297245.5\n 1423297253.5\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"retrypy/retry.py\", line 63, in call\n wait,\n File \"retrypy/retry.py\", line 29, in _retry\n raise previous_exception\n Exception: House\n\n**Incremental**::\n\n import time\n from retrypy import retry, delay\n\n def dummy_func():\n print time.time()\n raise Exception(\"House\")\n\n retry.call(dummy_func, wait=delay.incremental(\n start_at=1,\n step=1,\n ))\n\nOutput (wait times: 1s, 2s, 3s, 4s)::\n\n 1423297301.64\n 1423297302.64\n 1423297304.64\n 1423297307.65\n 1423297311.65\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"retrypy/retry.py\", line 63, in call\n wait,\n File \"retrypy/retry.py\", line 29, in _retry\n raise previous_exception\n Exception: House\n\n\nCustom Delay Functions:\n-----------------------\nYou can write your own delay functions, their only requirements are that they take an ``Integer`` and return a ``Number`` of seconds to wait.\n\n::\n\n def custom_delay(call_count):\n if call_count == 1:\n # don't wait at all the first time\n return 0\n\n # wait 4, 8, 16, 32\n return 2 ** call_count\n\n \nBuiltin Exception Checkers:\n---------------------------\n\nException Checkers can be used to check if you want to retry a specific exception. If the check function returns true then the exception is retryable otherwise we will not catch the exception and retry. The available **checkers** are: ``message_equals``, ``message_contains``, and ``message_matches``.\n\n**message_equals**, will match any ``Exception`` with a message that is identical to the string provided.\n\n**message_contains**, will match any ``Exception`` with a message that contains the string provided.\n\n**message_matches**, will match any ``Exception`` with a message that matches the regex provided. The regex may be passed as a string or a compiled regex pattern.\n\n\nCustom Exception Checkers:\n--------------------------\n\nYou can write your own exception checkers, their only requirements are that they: take an ``Exception`` and an ``Integer`` as parameters. They should return True if the exception is retryable otherwise False.\n\n::\n\n def custom_matcher(e, call_count):\n # never fail their first time no matter what\n if call_count == 1:\n return True\n\n # only retry errors with Bob Barker in the message.\n return \"Bob Barker\" in str(e):\n\n\nInstallation:\n-------------\n\n::\n\n >> pip install retrypy\n\nDevelopment:\n------------\n\n::\n\n >> git clone https://github.com/toddsifleet/retrypy\n >> cd retrypy\n >> make bootstrap\n >> make\n\nLicense:\n--------\n\nSee LICENSE\n\n.. |Travis Test Status| image:: https://travis-ci.org/toddsifleet/retrypy.svg?branch=master\n :target: https://travis-ci.org/toddsifleet/retrypy\n\n.. |PyPi Version| image:: https://badge.fury.io/py/retrypy.svg\n :target: http://badge.fury.io/py/retrypy", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/toddsifleet/retrypy", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "retrypy", "package_url": "https://pypi.org/project/retrypy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/retrypy/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/toddsifleet/retrypy" }, "release_url": "https://pypi.org/project/retrypy/0.0.33/", "requires_dist": null, "requires_python": null, "summary": "Python retry utility", "version": "0.0.33" }, "last_serial": 1418695, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "4b10cd673d963f68df32350939100ca6", "sha256": "b0ae8191859a962f17980c986f378ceae3e1c95d51293596d0a394ef81172be5" }, "downloads": -1, "filename": "retrypy-0.0.01.tar.gz", "has_sig": false, "md5_digest": "4b10cd673d963f68df32350939100ca6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2465, "upload_time": "2014-09-16T15:02:06", "url": "https://files.pythonhosted.org/packages/56/de/09565641dd77aee3c1d3ef17be3db32f060b1a232d09b0a68235b676ba90/retrypy-0.0.01.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "dbca9b978b3710396e3562398969c0f7", "sha256": "dee6bcfb15ffdf95dba371f795b9999bb7146374b782d040e6d711ee534d7b60" }, "downloads": -1, "filename": "retrypy-0.0.2.tar.gz", "has_sig": false, "md5_digest": "dbca9b978b3710396e3562398969c0f7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3215, "upload_time": "2014-10-29T02:08:29", "url": "https://files.pythonhosted.org/packages/54/51/7ffc43b8a93c631b5bf63d771f4dc4295c03ce8849445d41d3ea7570d941/retrypy-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "eda35dfbcefc3193b9ca5896e1756ab8", "sha256": "c08504c435e08f80ff3cbe0d1044692cd644a5e98df7c0a2481a3a11835b84d7" }, "downloads": -1, "filename": "retrypy-0.0.3.tar.gz", "has_sig": false, "md5_digest": "eda35dfbcefc3193b9ca5896e1756ab8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3223, "upload_time": "2014-10-30T01:48:56", "url": "https://files.pythonhosted.org/packages/fc/6a/ce1f47385d995649ad90f3c1ed758a60daaadef6f8da6eb2133a86935fea/retrypy-0.0.3.tar.gz" } ], "0.0.31": [ { "comment_text": "", "digests": { "md5": "7e44ad7af1908d3a6b99a41c7a8a8f76", "sha256": "bfe43c756a8ff4bddb0b7c7681a99d495193f762f57872c3dc4c873a9c944acc" }, "downloads": -1, "filename": "retrypy-0.0.31.tar.gz", "has_sig": false, "md5_digest": "7e44ad7af1908d3a6b99a41c7a8a8f76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3606, "upload_time": "2014-11-03T04:16:24", "url": "https://files.pythonhosted.org/packages/aa/e0/22ea807d034cf0ba7d458bbab98f1be829f0f80c73ed138f712b7cb6da2d/retrypy-0.0.31.tar.gz" } ], "0.0.32": [ { "comment_text": "", "digests": { "md5": "79a2eae6e88b7cde47602ba088b49feb", "sha256": "cc7b9bed5573716f5e7fc6f4ea581e2f8276475aa1df05c63fa1008527c28116" }, "downloads": -1, "filename": "retrypy-0.0.32.tar.gz", "has_sig": false, "md5_digest": "79a2eae6e88b7cde47602ba088b49feb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4520, "upload_time": "2015-02-07T09:27:28", "url": "https://files.pythonhosted.org/packages/c4/4a/5c27969c7cfbaa80a7e1de4d0ceb7985a41b2c36f2939da568f9337340f5/retrypy-0.0.32.tar.gz" } ], "0.0.33": [ { "comment_text": "", "digests": { "md5": "fa25c8172492d7968c662d122a5d9660", "sha256": "08693b096f0eaad6534e31fd7e82f6fdc854c49de642302ab26bb6d9c1e38a86" }, "downloads": -1, "filename": "retrypy-0.0.33.tar.gz", "has_sig": false, "md5_digest": "fa25c8172492d7968c662d122a5d9660", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5865, "upload_time": "2015-02-11T01:33:34", "url": "https://files.pythonhosted.org/packages/29/33/a6171d4a2b1761c4492a6bf1d7e91f1051524868e95fc5095c8d1e1ffe97/retrypy-0.0.33.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fa25c8172492d7968c662d122a5d9660", "sha256": "08693b096f0eaad6534e31fd7e82f6fdc854c49de642302ab26bb6d9c1e38a86" }, "downloads": -1, "filename": "retrypy-0.0.33.tar.gz", "has_sig": false, "md5_digest": "fa25c8172492d7968c662d122a5d9660", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5865, "upload_time": "2015-02-11T01:33:34", "url": "https://files.pythonhosted.org/packages/29/33/a6171d4a2b1761c4492a6bf1d7e91f1051524868e95fc5095c8d1e1ffe97/retrypy-0.0.33.tar.gz" } ] }