def timeout_after(secs):
"""Decorator to timeout a function.
It raises a gevent.Timeout exception after the specified seconds in
the decorated function. The timeout will work only if the decorated
function yields, e.g. performing blocking operations through gevent.
"""
def timeout_enforced(f):
@wraps(f)
def g(*args, **kwargs):
return gevent.with_timeout(secs, f, *args, **kwargs)
return g
return timeout_enforced
评论列表
文章目录