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

Function callAsync

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

Source from the content-addressed store, hash-verified

46# If the function called again within the rate limit interval then previous queued call will be dropped
47# Return: Immediately gevent thread
48def callAsync(event, allowed_again=10, func=None, *args, **kwargs):
49 if isAllowed(event, allowed_again): # Not called recently, call it now
50 called(event)
51 # print "Calling now"
52 return gevent.spawn(func, *args, **kwargs)
53 else: # Called recently, schedule it for later
54 time_left = allowed_again - max(0, time.time() - called_db[event])
55 log.debug("Added to queue (%.2fs left): %s " % (time_left, event))
56 if not queue_db.get(event): # Function call not queued yet
57 thread = gevent.spawn_later(time_left, lambda: callQueue(event)) # Call this function later
58 queue_db[event] = (func, args, kwargs, thread)
59 return thread
60 else: # Function call already queued, just update the parameters
61 thread = queue_db[event][3]
62 queue_db[event] = (func, args, kwargs, thread)
63 return thread
64
65
66# Rate limit and delay function call if needed

Callers 1

RateLimit.pyFile · 0.85

Calls 4

isAllowedFunction · 0.85
calledFunction · 0.85
callQueueFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected