def __call__(self, func):
func_logger = logging.getLogger(func.__module__)
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
request = kwargs.get('request')
if request:
_of = getattr(func, 'original', func)
if 'request' not in _of.__code__.co_varnames:
del kwargs['request']
response = kwargs.get('response')
if response:
_of = getattr(func, 'original', func)
if 'response' not in _of.__code__.co_varnames:
del kwargs['response']
try:
if self.timeout:
with gevent.Timeout(self.timeout):
return self._process(func, args, kwargs, request, response)
else:
return self._process(func, args, kwargs, request, response)
except falcon.http_status.HTTPStatus:
raise
except Exception as e:
return self._process_exception_output(e, func_logger, request, response, args, kwargs)
finally:
execution_time = (time.time() - start) * 1000
self._finish_exec(execution_time, func_logger, args, kwargs, request, func)
return self._gevent_wrapper(wrapper)
评论列表
文章目录