BGPSpeaker/base: Stop child activity by name

This patch enables Activity base to stop the child activity by name.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWASE Yusuke 2016-12-16 15:17:42 +09:00 committed by FUJITA Tomonori
parent 27b253d06e
commit 8555dda0f2

View File

@ -257,21 +257,24 @@ class Activity(object):
"""
hub.sleep(seconds)
def _stop_child_activities(self):
def _stop_child_activities(self, name=None):
"""Stop all child activities spawn by this activity.
"""
# Makes a list copy of items() to avoid dictionary size changed
# during iteration
for child_name, child in list(self._child_activity_map.items()):
if name is not None and name != child_name:
continue
LOG.debug('%s: Stopping child activity %s ', self.name, child_name)
if child.started:
child.stop()
self._child_activity_map.pop(child_name, None)
def _stop_child_threads(self, name=None):
"""Stops all threads spawn by this activity.
"""
for thread_name, thread in list(self._child_thread_map.items()):
if not name or thread_name is name:
if name is not None and thread_name is name:
LOG.debug('%s: Stopping child thread %s',
self.name, thread_name)
thread.kill()