Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import functools
- def my_retry(function):
- @functools.wraps(function)
- def wrapped(*args, **kwargs):
- print("my_retry calls", function.__name__)
- return function(*args, **kwargs)
- return wrapped
- def another_retry(function):
- @functools.wraps(function)
- def wrapped(*args, **kwargs):
- print("another_retry calls", function.__name__)
- return function(*args, **kwargs)
- return wrapped
- class ApiClient:
- def __init__(self, retry_function=None):
- # self.retry_function = my_retry
- # if retry_function:
- # self.retry_function = retry_function
- pass
- @my_retry
- def execute_hoge_api(self):
- print("hoge!")
- @my_retry
- def execute_fuga_api(self):
- print("fuga!")
- def main():
- ac = ApiClient()
- ac.execute_hoge_api()
- ac.execute_fuga_api()
- bc = ApiClient(retry_function=another_retry)
- bc.execute_hoge_api()
- bc.execute_fuga_api()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement