Created
February 25, 2020 18:26
-
-
Save alexeyproskuryakov/ea68450c0607819572cae5cd77fba24e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def exec_limiter(max_count): | |
def decorator(f): | |
def wrapper(*args, **kwargs): | |
wrapper.counter += 1 | |
if wrapper.counter <= max_count: | |
f(*args, **kwargs) | |
else: | |
raise Exception(f'Can not execute {f} with {args, kwargs} more than {max_count} times.') | |
wrapper.counter = 0 | |
return wrapper | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment