MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / call

Function call

src/util/RateLimit.py:68–82  ·  view source on GitHub ↗
(event, allowed_again=10, func=None, *args, **kwargs)

Source from the content-addressed store, hash-verified

66# Rate limit and delay function call if needed
67# Return: Wait for execution/delay then return value
68def call(event, allowed_again=10, func=None, *args, **kwargs):
69 if isAllowed(event): # Not called recently, call it now
70 called(event)
71 # print "Calling now", allowed_again
72 return func(*args, **kwargs)
73
74 else: # Called recently, schedule it for later
75 time_left = max(0, allowed_again - (time.time() - called_db[event]))
76 # print "Time left: %s" % time_left, args, kwargs
77 log.debug("Calling sync (%.2fs left): %s" % (time_left, event))
78 called(event, time_left)
79 time.sleep(time_left)
80 back = func(*args, **kwargs)
81 called(event)
82 return back
83
84
85# Cleanup expired events every 3 minutes

Callers 2

RateLimit.pyFile · 0.85
publishFunction · 0.85

Calls 2

isAllowedFunction · 0.85
calledFunction · 0.85

Tested by

no test coverage detected