Raise KeyboardInterrupt on SIGTERM - Workaround
Catch SIGTERM signal and call the signal handler method. The signal handler then raises KeyboardInterrupt. The KeyboardInterrupt won't be caught by any 'except Exception' clauses. Without this the service does not stop periodic workers, tear down pxe filters etc as it is supposed to on shutdown. NOTE: Calling shutdown() directly from the signal handler causes the below error. This is why the signal handler raises KeyboardInterrupt. AssertionError: Cannot switch to MAINLOOP from MAINLOOP Related-Bug: #1765700 Story: 2001890 Task: 14374 Change-Id: If0e24eae767b7806243fa4ae34fedb30ae9af25a
This commit is contained in:
parent
be3f7eec18
commit
737dbeae11
@ -43,6 +43,7 @@ class WSGIService(object):
|
||||
self._periodics_worker = None
|
||||
self._shutting_down = semaphore.Semaphore()
|
||||
signal.signal(signal.SIGHUP, self._handle_sighup)
|
||||
signal.signal(signal.SIGTERM, self._handle_sigterm)
|
||||
|
||||
def _init_middleware(self):
|
||||
"""Initialize WSGI middleware.
|
||||
@ -198,6 +199,12 @@ class WSGIService(object):
|
||||
def _handle_sighup(self, *args):
|
||||
eventlet.spawn(self._handle_sighup_bg, *args)
|
||||
|
||||
def _handle_sigterm(self, *args):
|
||||
# This is a workaround to ensure that shutdown() is done when recieving
|
||||
# SIGTERM. Raising KeyboardIntrerrupt which won't be caught by any
|
||||
# 'except Exception' clauses.
|
||||
raise KeyboardInterrupt
|
||||
|
||||
|
||||
def periodic_clean_up(): # pragma: no cover
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user