Package: pyrtout
Python TimeoutTimeout & retry functions in Python with a single line of codeExplore the docs »·Report Bug·Request Feature·Table of ContentsAbout The ProjectGetting StartedInstallationUsageBasic UsageAdvanced UsageRoadmapContributingLicenseContactAbout The ProjectThis is a Python package that provides decorators for adding timeout and retry functionality to your functions. With just one line of code, you can easily set a timeout for your function and choose to retry it any number of times in case of timeout.(back to top)Getting StartedThis is an example of how you may give instructions on setting up your project locally.
To get a local copy up and running follow these simple example steps.InstallationBuild from sourceClone the repositorygitclonegithub.com/radioactive11/pyrtoutRun the following command to install the projectpython3setup.pyinstallInstall usingpipTo install the function using pip, runpip3installpyrtout(back to top)UsageBasic UsageTo set timeout for a function, import the module usingfrom libtimeout import Timeout.Create a Timeout object class with the following parameters:`timeout_limit`: The time limit for the function to run (in seconds). Default is 10 seconds.

  `retry_limit`: The number of times to retry the function in case of timeout. Deafult is 0.Use thebindmethod to bind the timeout decorator to the function you want to set timeout for. This returns a new function with the timeout decorator applied.Call the new function with the same parameters as the original function.ExamplefromlibtimeoutimportTimeouttimeout_=Timeout(timeout_limit=5,retry_limit=2)@timeout_.bind()defmy_function(a,b):# Do somethingreturna+bmy_function(1,2)Advanced UsageBy default, the timeout decorator raises a TimeoutError in case of timeout. You can change this behavior by passing the following parameters:timeout_exception: The exception to raise in case of timeout. This must be a subclass of Exception.timeout_handler: The function to call in case of timeout. This must raise the exception specified in timeout_exception.ExamplefromlibtimeoutimportTimeoutclassCustomException(Exception):passdefcustom_handler():# do something like deleting partial downloaded files etc.raiseCustomException("Custom exception raised")timeout_=Timeout(timeout_limit=60,retry_limit=2,timeout_exception=CustomException,timeout_handler=custom_handler)@timeout_.bind()defdownload_large_file(url):# Download filereturn(back to top)Roadmap[] Add retry with backoff[] Add multi-threading supportSee theopen issuesfor a full list of proposed features (and known issues).(back to top)ContributingContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make aregreatly appreciated.If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull Request(back to top)LicenseDistributed under the MIT License. SeeLICENSE.txtfor more information.(back to top)ContactArijit Roy -@radioactive11-roy.arijit@icloud.comProject Link:https://github.com/your_username/repo_namehttps://github.com/radioactive11/pyrtout(back to top)