Skip to content

Commit

Permalink
Reap child processes gracefully if greenlet thread gets killed
Browse files Browse the repository at this point in the history
If ProcessLauncher is run from within a thread we should be able to
call wait after the thread is killed to reap the child processes.
Catching this exception and then proceeding to the cleanup phase
accomplishes this.

Closes-Bug: #1282206
Change-Id: I9c863864c25c0478b720fc57cf0dccbe9bc9d9f6
  • Loading branch information
Carl Baldwin committed Feb 25, 2014
1 parent b154ff8 commit 3c389e9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions openstack/common/service.py
Expand Up @@ -384,19 +384,22 @@ def wait(self):
LOG.debug('Full set of CONF:')
CONF.log_opt_values(LOG, std_logging.DEBUG)

while True:
self.handle_signal()
self._respawn_children()
if self.sigcaught:
signame = _signo_to_signame(self.sigcaught)
LOG.info(_LI('Caught %s, stopping children'), signame)
if not _is_sighup_and_daemon(self.sigcaught):
break

for pid in self.children:
os.kill(pid, signal.SIGHUP)
self.running = True
self.sigcaught = None
try:
while True:
self.handle_signal()
self._respawn_children()
if self.sigcaught:
signame = _signo_to_signame(self.sigcaught)
LOG.info(_LI('Caught %s, stopping children'), signame)
if not _is_sighup_and_daemon(self.sigcaught):
break

for pid in self.children:
os.kill(pid, signal.SIGHUP)
self.running = True
self.sigcaught = None
except eventlet.greenlet.GreenletExit:
LOG.info(_("Wait called after thread killed. Cleaning up."))

for pid in self.children:
try:
Expand Down

0 comments on commit 3c389e9

Please sign in to comment.