python/sleeping_decorator.py

18 lines
406 B
Python

import time
def sleep_decorator(seconds):
def decorator(func):
def wrapper(*args, **kwargs):
print(f"Sleeping for {seconds} seconds before executing '{func.__name__}'")
time.sleep(seconds)
return func(*args, **kwargs)
return wrapper
return decorator
@sleep_decorator(5)
def my_function():
print("Function executed!")
# Usage
my_function()