mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 14:51:22 +00:00
Make AsyncRateLimiter thread safe
This commit is contained in:
parent
4679a3494c
commit
128f48702a
@ -59,17 +59,23 @@ class RateLimiter:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
# TODO document this
|
||||||
class AsyncRateLimiter(RateLimiter):
|
class AsyncRateLimiter(RateLimiter):
|
||||||
def __init__(self, rate_per_second, ioloop_factory):
|
def __init__(self, rate_per_second, ioloop_factory):
|
||||||
self._ioloop_factory = ioloop_factory
|
self._ioloop_factory = ioloop_factory
|
||||||
self._ioloop = None
|
self._ioloop = None
|
||||||
self._last_callback = None
|
self._last_callback = None
|
||||||
|
|
||||||
|
self._make_action_thread_safe()
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
rate_per_second=rate_per_second,
|
rate_per_second=rate_per_second,
|
||||||
action=self.async_action
|
action=self.async_action
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _make_action_thread_safe(self):
|
||||||
|
self.async_action = partial(self.ioloop.add_callback, self.async_action)
|
||||||
|
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def ioloop(self):
|
def ioloop(self):
|
||||||
return self._ioloop_factory()
|
return self._ioloop_factory()
|
||||||
|
Loading…
Reference in New Issue
Block a user