def limit(limit, every=<NUM_LIT:1>):
def limitdecorator(fn):<EOL><INDENT>"""<STR_LIT>"""<EOL>semaphore = _threading.Semaphore(limit)<EOL>@_functools.wraps(fn)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>semaphore.acquire()<EOL>try:<EOL><INDENT>return fn(*args, **kwargs)<EOL><DEDENT>finally:                   <EOL><INDENT>timer = _threading.Timer(every, semaphore.release)<EOL>timer.setDaemon(True)  <EOL>timer.start()<EOL><DEDENT><DEDENT>return wrapper<EOL><DEDENT>return limitdecorator<EOL>
This decorator factory creates a decorator that can be applied to
       functions in order to limit the rate the function can be invoked.
       The rate is `limit` over `every`, where limit is the number of
       invocation allowed every `every` seconds.
       limit(4, 60) creates a decorator that limit the function calls
       to 4 per minute. If not specified, every defaults to 1 second.