Hello, my name is urain39!
I am a developer who like to writing programs in Python, JavaScript, and C-Like Languages :)
License: Apache License 2.0
from functools import wraps
def retry(errors, max_count=3, callback=None, is_method=False):
"""
@param errors: any class which based on `Exception`
@param max_count: optional, the max retry count
@param callback: optional, be called with `retry count` before retry
@param is_method: optional, useful when you want to wrap a method
Examples:
@retry(ZeroDivisionError, 3,
lambda cnt, err: print(cnt, err))
def _():
0/0
_()
"""
# count = 0
count = [0]
print("(outer)count[0] = {0}".format(count[0]))
# pylint: disable=invalid-name
def fn_wrapper(fn):
@wraps(fn)
def wrapped_fn(*args, **kwargs):
result = None
if is_method:
self = args[0]
while True:
try:
count[0] += 1
result = fn(*args, **kwargs)
break
# pylint: disable=invalid-name
except errors as err:
if count[0] <= max_count:
if callable(callback):
if is_method:
callback(self, count[0], err)
else: # function
print("(inner)count[0] = {0}".format(count[0]))
callback(count[0], err)
continue
else:
raise err
return result
return wrapped_fn
return fn_wrapper
def handler(cnt, error, **kwargs):
if error is Tiemeout:
...
elif error is xxxError:
...
else
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.