py-timelimit


Namepy-timelimit JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/radioactive11/python-timeout
SummaryTimeout & retry functions in Python with a single line of code
upload_time2023-03-24 19:12:54
maintainer
docs_urlNone
authorradioactive11
requires_python>=3.7
license
keywords python timeout retry kill signal unix
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- Improved compatibility of back to top link: See: https://github.com/radioactive11/python-timeout/pull/73 -->
<a name="readme-top"></a>

<!-- PROJECT LOGO -->
<br />
<div align="center">
  <h3 align="center">Python Timeout</h3>

  <p align="center">
    Timeout & retry functions in Python with a single line of code
    <br />
    <a href="https://github.com/radioactive11/python-timeout"><strong>Explore the docs »</strong></a>
    <br />
    ·
    <a href="https://github.com/radioactive11/python-timeout/issues">Report Bug</a>
    ·
    <a href="https://github.com/radioactive11/python-timeout/issues">Request Feature</a>
    ·
  </p>
</div>



<!-- TABLE OF CONTENTS -->
<details>
  <summary>Table of Contents</summary>
  <ol>
    <li>
      <a href="#about-the-project">About The Project</a>
    </li>
    <li>
      <a href="#getting-started">Getting Started</a>
      <ul>
        <li><a href="#installation">Installation</a></li>
      </ul>
    </li>
    <li><a href="#usage">Usage</a></li>
    <ul>
        <li><a href="#basic-usage">Basic Usage</a></li>
        <li><a href="#advanced-usage">Advanced Usage</a></li>
    </ul>
    <li><a href="#roadmap">Roadmap</a></li>
    <li><a href="#contributing">Contributing</a></li>
    <li><a href="#license">License</a></li>
    <li><a href="#contact">Contact</a></li>
  </ol>
</details>



<!-- ABOUT THE PROJECT -->
## About The Project

<img src="./.github/banner.png">

This 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.

<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- GETTING STARTED -->
## Getting Started

This 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.


### Installation

#### Build from source

1. Clone the repository

```sh
git clone github.com/radioactive11/python-timeout
```

2. Run the following command to install the project
```sh
python3 setup.py install
```


#### Install using `pip`

To install the function using pip, run

```sh
pip3 install python-timeout
```


<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- USAGE EXAMPLES -->
## Usage

### Basic Usage

- To set timeout for a function, import the module using `from 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 the `bind` method 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.

*Example*

```python
from libtimeout import Timeout


timeout_ = Timeout(timeout_limit=5, retry_limit=2)

@timeout_.bind()
def my_function(a, b):
    # Do something
    return a + b

my_function(1, 2)

```
<br>

### Advanced Usage

By 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.

*Example*

```python
from libtimeout import Timeout

class CustomException(Exception):
    pass

def custom_handler():
    # do something like deleting partial downloaded files etc.
    raise CustomException("Custom exception raised")

timeout_ = Timeout(timeout_limit=60, retry_limit=2, timeout_exception=CustomException, timeout_handler=custom_handler)

@timeout_.bind()
def download_large_file(url):
    # Download file
    return

```



<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- ROADMAP -->
## Roadmap

- [] Add retry with backoff
- [] Add multi-threading support


See the [open issues](https://github.com/radioactive11/python-timeout/issues) for a full list of proposed features (and known issues).

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly 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!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- LICENSE -->
## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- CONTACT -->
## Contact

Arijit Roy - [@_radioactive11_](https://twitter.com/_radioactive11_) - roy.arijit@icloud.com

Project Link: [https://github.com/your_username/repo_namehttps://github.com/radioactive11/python-timeout](https://github.com/radioactive11/python-timeout)

<p align="right">(<a href="#readme-top">back to top</a>)</p>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/radioactive11/python-timeout",
    "name": "py-timelimit",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "python timeout retry kill signal unix",
    "author": "radioactive11",
    "author_email": "Arijit Roy <roy.arijit@icloud.com>",
    "download_url": "https://files.pythonhosted.org/packages/e1/26/e7aeeea1936732f6096e94b1c91c02caf1015fef18f6891c71a538a65587/py-timelimit-1.0.1.tar.gz",
    "platform": null,
    "description": "<!-- Improved compatibility of back to top link: See: https://github.com/radioactive11/python-timeout/pull/73 -->\n<a name=\"readme-top\"></a>\n\n<!-- PROJECT LOGO -->\n<br />\n<div align=\"center\">\n  <h3 align=\"center\">Python Timeout</h3>\n\n  <p align=\"center\">\n    Timeout & retry functions in Python with a single line of code\n    <br />\n    <a href=\"https://github.com/radioactive11/python-timeout\"><strong>Explore the docs \u00bb</strong></a>\n    <br />\n    \u00b7\n    <a href=\"https://github.com/radioactive11/python-timeout/issues\">Report Bug</a>\n    \u00b7\n    <a href=\"https://github.com/radioactive11/python-timeout/issues\">Request Feature</a>\n    \u00b7\n  </p>\n</div>\n\n\n\n<!-- TABLE OF CONTENTS -->\n<details>\n  <summary>Table of Contents</summary>\n  <ol>\n    <li>\n      <a href=\"#about-the-project\">About The Project</a>\n    </li>\n    <li>\n      <a href=\"#getting-started\">Getting Started</a>\n      <ul>\n        <li><a href=\"#installation\">Installation</a></li>\n      </ul>\n    </li>\n    <li><a href=\"#usage\">Usage</a></li>\n    <ul>\n        <li><a href=\"#basic-usage\">Basic Usage</a></li>\n        <li><a href=\"#advanced-usage\">Advanced Usage</a></li>\n    </ul>\n    <li><a href=\"#roadmap\">Roadmap</a></li>\n    <li><a href=\"#contributing\">Contributing</a></li>\n    <li><a href=\"#license\">License</a></li>\n    <li><a href=\"#contact\">Contact</a></li>\n  </ol>\n</details>\n\n\n\n<!-- ABOUT THE PROJECT -->\n## About The Project\n\n<img src=\"./.github/banner.png\">\n\nThis 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.\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n\n<!-- GETTING STARTED -->\n## Getting Started\n\nThis is an example of how you may give instructions on setting up your project locally.\nTo get a local copy up and running follow these simple example steps.\n\n\n### Installation\n\n#### Build from source\n\n1. Clone the repository\n\n```sh\ngit clone github.com/radioactive11/python-timeout\n```\n\n2. Run the following command to install the project\n```sh\npython3 setup.py install\n```\n\n\n#### Install using `pip`\n\nTo install the function using pip, run\n\n```sh\npip3 install python-timeout\n```\n\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n\n<!-- USAGE EXAMPLES -->\n## Usage\n\n### Basic Usage\n\n- To set timeout for a function, import the module using `from libtimeout import Timeout`.\n\n- Create a Timeout object class with the following parameters:\n\n        `timeout_limit`: The time limit for the function to run (in seconds). Default is 10 seconds.\n\n        `retry_limit`: The number of times to retry the function in case of timeout. Deafult is 0.\n\n- Use the `bind` method to bind the timeout decorator to the function you want to set timeout for. This returns a new function with the timeout decorator applied.\n\n- Call the new function with the same parameters as the original function.\n\n*Example*\n\n```python\nfrom libtimeout import Timeout\n\n\ntimeout_ = Timeout(timeout_limit=5, retry_limit=2)\n\n@timeout_.bind()\ndef my_function(a, b):\n    # Do something\n    return a + b\n\nmy_function(1, 2)\n\n```\n<br>\n\n### Advanced Usage\n\nBy default, the timeout decorator raises a TimeoutError in case of timeout. You can change this behavior by passing the following parameters:\n\ntimeout_exception: The exception to raise in case of timeout. This must be a subclass of Exception.\n\ntimeout_handler: The function to call in case of timeout. This must raise the exception specified in timeout_exception.\n\n*Example*\n\n```python\nfrom libtimeout import Timeout\n\nclass CustomException(Exception):\n    pass\n\ndef custom_handler():\n    # do something like deleting partial downloaded files etc.\n    raise CustomException(\"Custom exception raised\")\n\ntimeout_ = Timeout(timeout_limit=60, retry_limit=2, timeout_exception=CustomException, timeout_handler=custom_handler)\n\n@timeout_.bind()\ndef download_large_file(url):\n    # Download file\n    return\n\n```\n\n\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n\n\n<!-- ROADMAP -->\n## Roadmap\n\n- [] Add retry with backoff\n- [] Add multi-threading support\n\n\nSee the [open issues](https://github.com/radioactive11/python-timeout/issues) for a full list of proposed features (and known issues).\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n\n\n<!-- CONTRIBUTING -->\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\nIf 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\".\nDon't forget to give the project a star! Thanks again!\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n\n\n<!-- LICENSE -->\n## License\n\nDistributed under the MIT License. See `LICENSE.txt` for more information.\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n\n\n<!-- CONTACT -->\n## Contact\n\nArijit Roy - [@_radioactive11_](https://twitter.com/_radioactive11_) - roy.arijit@icloud.com\n\nProject Link: [https://github.com/your_username/repo_namehttps://github.com/radioactive11/python-timeout](https://github.com/radioactive11/python-timeout)\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Timeout & retry functions in Python with a single line of code",
    "version": "1.0.1",
    "split_keywords": [
        "python",
        "timeout",
        "retry",
        "kill",
        "signal",
        "unix"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ddbeaf67de7149ab3fccd208321351f260391daece902b62a628a387f70c42c6",
                "md5": "cbee2fa7a64c9279361a3ce14b2bf2f3",
                "sha256": "0e38ae0b5b79e2aba0681d1b190d853947e6a6c491739a09315b07d054cd159a"
            },
            "downloads": -1,
            "filename": "py_timelimit-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cbee2fa7a64c9279361a3ce14b2bf2f3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4115,
            "upload_time": "2023-03-24T19:12:52",
            "upload_time_iso_8601": "2023-03-24T19:12:52.794037Z",
            "url": "https://files.pythonhosted.org/packages/dd/be/af67de7149ab3fccd208321351f260391daece902b62a628a387f70c42c6/py_timelimit-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e126e7aeeea1936732f6096e94b1c91c02caf1015fef18f6891c71a538a65587",
                "md5": "c15d7309b35570718d36e926e369a809",
                "sha256": "4e11807ee1a1dac6137c99db4dd234e2f73bf557b1ab572bb895ff01237df933"
            },
            "downloads": -1,
            "filename": "py-timelimit-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c15d7309b35570718d36e926e369a809",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4573,
            "upload_time": "2023-03-24T19:12:54",
            "upload_time_iso_8601": "2023-03-24T19:12:54.294249Z",
            "url": "https://files.pythonhosted.org/packages/e1/26/e7aeeea1936732f6096e94b1c91c02caf1015fef18f6891c71a538a65587/py-timelimit-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-24 19:12:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "radioactive11",
    "github_project": "python-timeout",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "py-timelimit"
}
        
Elapsed time: 0.13161s