Commit f59dce3e authored by Guido Trotter's avatar Guido Trotter
Browse files

Mainloop: handle SIGINT as well (and terminate)



This is needed if daemons are in the foreground, and get ctrl+c-ed by
the user. Also add unittests to make sure the correct signals terminate
the mainloop.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent d021e478
......@@ -168,6 +168,7 @@ class Mainloop(object):
@utils.SignalHandled([signal.SIGCHLD])
@utils.SignalHandled([signal.SIGTERM])
@utils.SignalHandled([signal.SIGINT])
def Run(self, signal_handlers=None):
"""Runs the mainloop.
......@@ -194,7 +195,7 @@ class Mainloop(object):
handler = signal_handlers[sig]
if handler.called:
self._CallSignalWaiters(sig)
running = (sig != signal.SIGTERM)
running = sig not in (signal.SIGTERM, signal.SIGINT)
handler.Clear()
def _CallSignalWaiters(self, signum):
......
......@@ -56,6 +56,16 @@ class TestMainloop(testutils.GanetiTestCase):
self.mainloop.Run() # terminates by _SendSig being scheduled
self.assertEquals(self.sendsig_events, [signal.SIGTERM])
def testTerminatingSignals(self):
self.mainloop.scheduler.enter(0.1, 1, self._SendSig, [signal.SIGCHLD])
self.mainloop.scheduler.enter(0.2, 1, self._SendSig, [signal.SIGINT])
self.mainloop.Run()
self.assertEquals(self.sendsig_events, [signal.SIGCHLD, signal.SIGINT])
self.mainloop.scheduler.enter(0.1, 1, self._SendSig, [signal.SIGTERM])
self.mainloop.Run()
self.assertEquals(self.sendsig_events, [signal.SIGCHLD, signal.SIGINT,
signal.SIGTERM])
def testSchedulerCancel(self):
handle = self.mainloop.scheduler.enter(0.1, 1, self._SendSig,
[signal.SIGTERM])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment