def _concurrent(func):
@wraps(func) # 加入这个的目的是保持原来方法的属性
def arg_wrapper(self, *args, **kwargs):
try:
jc = self.available_jc.pop()
# return f is function
f = getattr(jc, func.__name__)
r = f(*args, **kwargs)
self.available_jc.append(jc)
return r
except IndexError:
raise RuntimeError('Too many concurrent connections!'
'Try to increase the value of "max_concurrency", '
'currently =%d' % self.max_concurrency)
return arg_wrapper
@_concurrent
def subjective_judge(self, **kwargs):
pass
@property
@_concurrent
def server_status(self):
pass