summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2016-09-06 13:37:11 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-09-07 10:25:12 +0900
commite0e30d3d96eeda01f7c59ddb1773793994e830f4 (patch)
treebb7470189efe82649d206d75e760a651cf688c55
parent5d1d8648ab0830206523fb944f19a4805bba1d3d (diff)
BGPSpeaker: Shutdown BGPSpeaker gracefully
Currently, when BGPSpeaker instance calls 'core.stop', CORE_MANAGER fails to stop its own activities and outputs traceback, because the dictionaries which maps name to instance are changed during iteration. This patch makes a list copy of items() to avoid this problem and enable to shutdown gracefully. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/base.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/ryu/services/protocols/bgp/base.py b/ryu/services/protocols/bgp/base.py
index d34a9dcc..315ea27c 100644
--- a/ryu/services/protocols/bgp/base.py
+++ b/ryu/services/protocols/bgp/base.py
@@ -260,19 +260,17 @@ class Activity(object):
def _stop_child_activities(self):
"""Stop all child activities spawn by this activity.
"""
- # Iterating over items list instead of iteritems to avoid dictionary
- # changed size during iteration
- child_activities = self._child_activity_map.items()
- for child_name, child_activity in child_activities:
+ # Makes a list copy of items() to avoid dictionary size changed
+ # during iteration
+ for child_name, child in list(self._child_activity_map.items()):
LOG.debug('%s: Stopping child activity %s ', self.name, child_name)
- if child_activity.started:
- child_activity.stop()
+ if child.started:
+ child.stop()
def _stop_child_threads(self, name=None):
"""Stops all threads spawn by this activity.
"""
- child_threads = self._child_thread_map.items()
- for thread_name, thread in child_threads:
+ for thread_name, thread in list(self._child_thread_map.items()):
if not name or thread_name is name:
LOG.debug('%s: Stopping child thread %s',
self.name, thread_name)
@@ -282,14 +280,12 @@ class Activity(object):
def _close_asso_sockets(self):
"""Closes all the sockets linked to this activity.
"""
- asso_sockets = self._asso_socket_map.items()
- for sock_name, sock in asso_sockets:
+ for sock_name, sock in list(self._asso_socket_map.items()):
LOG.debug('%s: Closing socket %s - %s', self.name, sock_name, sock)
sock.close()
def _stop_timers(self):
- timers = self._timers.items()
- for timer_name, timer in timers:
+ for timer_name, timer in list(self._timers.items()):
LOG.debug('%s: Stopping timer %s', self.name, timer_name)
timer.stop()