Avoid runtime errors in zk node iterator
While iterating over zk nodes with node IDs from the from the node cache, there can be runtime errors when the cache was updated during the iteration process. (``RuntimeError: dictionary changed size during iteration``) Avoid this by iterating over a copy of the node IDs, rather than the dict_keys directly. Change-Id: Iecd88b4484cf48ea2127348bfb2905443eaaf49f
This commit is contained in:
parent
447547273b
commit
1a73a7a33e
@ -2271,7 +2271,12 @@ class ZooKeeper(object):
|
|||||||
cache.
|
cache.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
node_ids = self._cached_nodes.keys() if cached_ids else self.getNodes()
|
if cached_ids:
|
||||||
|
# get a copy of the keys view to avoid runtime errors in the event
|
||||||
|
# the _cached_nodes dict gets updated while iterating
|
||||||
|
node_ids = list(self._cached_nodes.keys())
|
||||||
|
else:
|
||||||
|
node_ids = self.getNodes()
|
||||||
|
|
||||||
for node_id in node_ids:
|
for node_id in node_ids:
|
||||||
node = self.getNode(node_id, cached=cached)
|
node = self.getNode(node_id, cached=cached)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user