Skip to content

Instantly share code, notes, and snippets.

@alexeyproskuryakov
Created February 25, 2020 18:26
Show Gist options
  • Save alexeyproskuryakov/ea68450c0607819572cae5cd77fba24e to your computer and use it in GitHub Desktop.
Save alexeyproskuryakov/ea68450c0607819572cae5cd77fba24e to your computer and use it in GitHub Desktop.
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