clocklock


Nameclocklock JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryA streamlined Python utility that enforces timeouts on your Python functions. It features a decorator and a function runner, both with provision for fallback functionality. Keep your code efficient and punctual, maintaining smooth control flow with ClockLock. Timing your Python functions has never been easier.
upload_time2024-01-28 18:37:23
maintainer
docs_urlNone
authorRam
requires_python>=3,<4
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ClockLock

A streamlined Python utility that gracefully enforces timeouts on your Python functions. Crafted with precision and simplicity, ClockLock lets you leash your function time execution with ease. With its featured decorator and function runner, both equipped with a fallback mechanism, maintaining a smooth control flow has never been more efficient.

## How It Works
ClockLock uses Python's concurrency mechanisms to keep your functions punctual. Providing an easy-to-use decorator and a direct function runner, your functions can be executed with a specified timeout limit - all within a few lines of code. If a function exceeds its time, a fallback function is triggered, facilitating a smooth control flow. Easy to set up and handy in its use, ClockLock guarantees your Python functions never overstay their welcome.

## Why ClockLock?
- **Graceful**: ClockLock manages function timeout smoothly and efficiently.
- **Fallback mechanism**: Provides an option to execute a fallback function if the primary function exceeds the given time.
- **Versatile**: Equally suited for small scripts and large applications.
- **Pythonic**: A clean, minimal, and familiar Python interface.

## Features
- **Decorator**: Simply annotate a function with `@clocklock.timeout(seconds=10)` to keep it in check.
- **Function runner**: Use `clocklock.timeout_fn(run_fn, timeout, fallback_fn, args, kwargs)` to control the execution of a function.
- **Fallback function**: Define a fallback function which gets triggered in case the primary function timeouts.

## Installation

Use pip to install:

```bash
pip install clocklock
```

Or, if you use Poetry:

```bash
poetry add clocklock
```

## Usage
First, import ClockLock:

```python
from clocklock import timeout, timeout_fn
```

Then, you can register a function for timeout:

```python
@timeout(seconds=1, fallback=lambda:"Fallback Task Complete")
def slow_function():
    time.sleep(2)
    return "done"

slow_function() # returns "Fallback Task Complete"
```
Or, use the function runner:
```python
def slow_function():
    time.sleep(2)
    return "done"

def fallback_func():
    print("Primary function exceeded time limit.")
timeout_fn(seconds=1, func=slow_function, fallback=fallback_func) # prints "Primary function exceeded time limit."
```

Please view the 'examples' directory for detailed usage examples.

## Contributing
We encourage you to contribute to ClockLock! Please check out the [Contributing to ClockLock guide](CONTRIBUTING.md) for guidelines about how to proceed.

## License
ClockLock is released under the [MIT License](LICENSE.md).


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "clocklock",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3,<4",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ram",
    "author_email": "r4mbhardwaj@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/14/cc/3836f0044ef1a5ba55b020e4a7738d43cbe8f43bba6c72b6bf148b82f058/clocklock-1.0.1.tar.gz",
    "platform": null,
    "description": "# ClockLock\n\nA streamlined Python utility that gracefully enforces timeouts on your Python functions. Crafted with precision and simplicity, ClockLock lets you leash your function time execution with ease. With its featured decorator and function runner, both equipped with a fallback mechanism, maintaining a smooth control flow has never been more efficient.\n\n## How It Works\nClockLock uses Python's concurrency mechanisms to keep your functions punctual. Providing an easy-to-use decorator and a direct function runner, your functions can be executed with a specified timeout limit - all within a few lines of code. If a function exceeds its time, a fallback function is triggered, facilitating a smooth control flow. Easy to set up and handy in its use, ClockLock guarantees your Python functions never overstay their welcome.\n\n## Why ClockLock?\n- **Graceful**: ClockLock manages function timeout smoothly and efficiently.\n- **Fallback mechanism**: Provides an option to execute a fallback function if the primary function exceeds the given time.\n- **Versatile**: Equally suited for small scripts and large applications.\n- **Pythonic**: A clean, minimal, and familiar Python interface.\n\n## Features\n- **Decorator**: Simply annotate a function with `@clocklock.timeout(seconds=10)` to keep it in check.\n- **Function runner**: Use `clocklock.timeout_fn(run_fn, timeout, fallback_fn, args, kwargs)` to control the execution of a function.\n- **Fallback function**: Define a fallback function which gets triggered in case the primary function timeouts.\n\n## Installation\n\nUse pip to install:\n\n```bash\npip install clocklock\n```\n\nOr, if you use Poetry:\n\n```bash\npoetry add clocklock\n```\n\n## Usage\nFirst, import ClockLock:\n\n```python\nfrom clocklock import timeout, timeout_fn\n```\n\nThen, you can register a function for timeout:\n\n```python\n@timeout(seconds=1, fallback=lambda:\"Fallback Task Complete\")\ndef slow_function():\n    time.sleep(2)\n    return \"done\"\n\nslow_function() # returns \"Fallback Task Complete\"\n```\nOr, use the function runner:\n```python\ndef slow_function():\n    time.sleep(2)\n    return \"done\"\n\ndef fallback_func():\n    print(\"Primary function exceeded time limit.\")\ntimeout_fn(seconds=1, func=slow_function, fallback=fallback_func) # prints \"Primary function exceeded time limit.\"\n```\n\nPlease view the 'examples' directory for detailed usage examples.\n\n## Contributing\nWe encourage you to contribute to ClockLock! Please check out the [Contributing to ClockLock guide](CONTRIBUTING.md) for guidelines about how to proceed.\n\n## License\nClockLock is released under the [MIT License](LICENSE.md).\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A streamlined Python utility that enforces timeouts on your Python functions. It features a decorator and a function runner, both with provision for fallback functionality. Keep your code efficient and punctual, maintaining smooth control flow with ClockLock. Timing your Python functions has never been easier.",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ede503e3bc8d8621c2b93a6f7f54b79a86c03afea27733dc23375a0d46fc6d1",
                "md5": "7250654da32934234d47e04c41fe24b8",
                "sha256": "67d739921c987b7311708720e5975b9f6379a22afb016f3f5057a86e7f0f67d7"
            },
            "downloads": -1,
            "filename": "clocklock-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7250654da32934234d47e04c41fe24b8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3,<4",
            "size": 4675,
            "upload_time": "2024-01-28T18:37:22",
            "upload_time_iso_8601": "2024-01-28T18:37:22.272874Z",
            "url": "https://files.pythonhosted.org/packages/1e/de/503e3bc8d8621c2b93a6f7f54b79a86c03afea27733dc23375a0d46fc6d1/clocklock-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14cc3836f0044ef1a5ba55b020e4a7738d43cbe8f43bba6c72b6bf148b82f058",
                "md5": "e19847f44a21d4650df682278df81887",
                "sha256": "1f690a5360cdce9b7be09c76382f6cd0cfebd248d96f7b50e0ee2b4c08914b46"
            },
            "downloads": -1,
            "filename": "clocklock-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e19847f44a21d4650df682278df81887",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3,<4",
            "size": 3710,
            "upload_time": "2024-01-28T18:37:23",
            "upload_time_iso_8601": "2024-01-28T18:37:23.919712Z",
            "url": "https://files.pythonhosted.org/packages/14/cc/3836f0044ef1a5ba55b020e4a7738d43cbe8f43bba6c72b6bf148b82f058/clocklock-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-28 18:37:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "clocklock"
}
        
Ram
Elapsed time: 0.23477s