Use a thread safe deque instead of a queue
Instead of using a queue like a deque just use a deque directly instead, a queue doesn't seem to add much value when its used like it was. Change-Id: I515c14bb16e18c4031f446c7176915c94b3fb8f4
This commit is contained in:
parent
c5e1c3f96f
commit
3f08c3e933
|
@ -59,7 +59,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
raise coordination.ToozError("operation error: %s" % (e))
|
||||
|
||||
self._group_members = collections.defaultdict(set)
|
||||
self._watchers = six.moves.queue.Queue()
|
||||
self._watchers = collections.deque()
|
||||
self._leader_locks = {}
|
||||
|
||||
def stop(self):
|
||||
|
@ -228,7 +228,7 @@ class KazooDriver(BaseZooKeeperDriver):
|
|||
# Copy function in case it's removed later from the
|
||||
# hook list
|
||||
hooks = copy.copy(self._hooks_join_group[group_id])
|
||||
self._watchers.put(
|
||||
self._watchers.append(
|
||||
lambda: hooks.run(
|
||||
coordination.MemberJoinedGroup(
|
||||
group_id,
|
||||
|
@ -238,7 +238,7 @@ class KazooDriver(BaseZooKeeperDriver):
|
|||
# Copy function in case it's removed later from the
|
||||
# hook list
|
||||
hooks = copy.copy(self._hooks_leave_group[group_id])
|
||||
self._watchers.put(
|
||||
self._watchers.append(
|
||||
lambda: hooks.run(
|
||||
coordination.MemberLeftGroup(
|
||||
group_id,
|
||||
|
@ -336,11 +336,8 @@ class KazooDriver(BaseZooKeeperDriver):
|
|||
|
||||
def run_watchers(self):
|
||||
ret = []
|
||||
while True:
|
||||
try:
|
||||
cb = self._watchers.get(block=False)
|
||||
except six.moves.queue.Empty:
|
||||
break
|
||||
while self._watchers:
|
||||
cb = self._watchers.popleft()
|
||||
ret.extend(cb())
|
||||
|
||||
for group_id in six.iterkeys(self._hooks_elected_leader):
|
||||
|
|
Loading…
Reference in New Issue