Skip to content

Commit

Permalink
Merge pull request #24 from sileht/on_dead_worker
Browse files Browse the repository at this point in the history
Fix sigterm during startup
  • Loading branch information
sileht committed Dec 21, 2018
2 parents 29b20ff + f529029 commit 0569adf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cotyledon/_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ def _shutdown(self):
self._got_sig_chld.set()
self._child_supervisor.join()

# NOTE(sileht): During startup if we receive SIGTERM, python
# multiprocess may fork the process after we send the killpg(0)
# To workaround the issue we sleep a bit, so multiprocess can finish
# its work.
time.sleep(0.1)

self._run_hooks('terminate')

LOG.debug("Killing services with signal SIGTERM")
Expand Down
12 changes: 12 additions & 0 deletions cotyledon/tests/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,17 @@ def on_dead_worker(service_id, worker_id, exit_code):
p.run()


def sigterm_during_init():

def kill():
os.kill(os.getpid(), signal.SIGTERM)

# Kill in 0.01 sec
threading.Timer(0.01, kill).start()
p = cotyledon.ServiceManager()
p.add(LigthService, 10)
p.run()


if __name__ == '__main__':
globals()[sys.argv[1]]()
9 changes: 9 additions & 0 deletions cotyledon/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,12 @@ def test_options(self):
b'DEBUG:cotyledon.oslo_config_glue:Full set of CONF:',
lines)
self.subp.terminate()


class TestTermDuringStartupCotyledon(Base):
name = 'sigterm_during_init'

def test_sigterm(self):
lines = self.hide_pids(self.get_lines())
self.assertIn(b'DEBUG:cotyledon._service_manager:Shutdown finish',
lines)

0 comments on commit 0569adf

Please sign in to comment.