Skip to main content

decorators utility

Project description

decoratorsutility

Introduction

This Python package provides decorators to handle exceptions, measure execution time, and set timeouts.

Installation

To install decoratorsutility, simply use pip:

pip install decoratorsutility

Usage Example

exception_dec

Decorator to handle exceptions by logging errors to a specified file path.

@exception_dec('module_name', '/path/to/logfile.log')
def function_name(*args, **kwargs):
    try:
        # Function execution
        return func(*args, **kwargs)
    except Exception as err:
        # Logs the error to the specified file path
        log_error(module=exc_mod, file_path=exc_path, error=err)
        logging.error(err)

repeat_on_error

Decorator to retry function execution a set number of times in case of exceptions.

@repeat_on_error(max_try=3, error_log='log/logfile.log', show_error=True)
def test_dummy(arg1:int):
    return arg1/0

timeout_decorator

Decorator to set a timeout for a function.

from decoratorsutility.decorators import timeout_decorator

@timeout_decorator(timeout=5)
def my_function():
    time.sleep(6)  # Simulate a long-running function
    return "Success!"

Documentation

The Sphinx-generated documentation for PathUtils can be found here.

Contribution

Feel free to contribute by submitting issues here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

decoratorsutility-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file decoratorsutility-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for decoratorsutility-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d90a422dd95947929f9c7b31e965c45c429e1bfea6e78cf627ab4c34f17499a
MD5 ac53af36d69caebd534c19d0c4e6f808
BLAKE2b-256 c6ca478011e8ed35edc5cf3bf2bf232d0c261dcf22839c885532d90f43e25f45

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page