
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
This Python package provides decorators to handle exceptions, measure execution time, and set timeouts.
To install decoratorsutility, simply use pip:
pip install decoratorsutility
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!"
The Sphinx-generated documentation for PathUtils can be found here.
Feel free to contribute by submitting issues here.
FAQs
decorators utility
We found that decoratorsutility demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.