Python
- 6 ответов
- 0 вопросов
7
Вклад в тег
import logging
LOG = logging.getLogger(__name__)
def handle_silently(function):
def wrapped(*args, **kwargs):
result = None
try:
result = function(*args, **kwargs)
except Exception as e:
LOG.error(
'{}(*{}, **{}) failed with exception {}'.format(
function.__name__, repr(args), repr(kwargs), repr(e)
)
)
return result
return wrapped
@handle_silently
def some_function(test):
return test / 0
def decorators_fabric(handler_function):
def decorator(function):
def wrapped(*args, **kwargs):
handler_function(function.__name__, repr(args), repr(kwargs))
return function(*args, **kwargs)
return wrapped
return decorator
@decorators_fabric(print)
def my_test_function(arg1, arg2):
return arg1 * arg2
result = Context.query.join(
Request, Request.context_id == Context.id_
).join(
Point, Point.request_id == Request.id_
).group_by(Context.id_).with_entities(
Context.field1, ...
func.count(Point.id_).label('points_count')
)