Socket
Socket
Sign inDemoInstall

decoratorsutility

Package Overview
Dependencies
2
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    decoratorsutility

decorators utility


Maintainers
1

Readme

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.

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc