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 <>
Reviewed-by: default avatarIustin Pop <>
parent d021e478
......@@ -168,6 +168,7 @@ class Mainloop(object):
def Run(self, signal_handlers=None):
"""Runs the mainloop.
......@@ -194,7 +195,7 @@ class Mainloop(object):
handler = signal_handlers[sig]
if handler.called:
running = (sig != signal.SIGTERM)
running = sig not in (signal.SIGTERM, signal.SIGINT)
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.assertEquals(self.sendsig_events, [signal.SIGCHLD, signal.SIGINT])
self.mainloop.scheduler.enter(0.1, 1, self._SendSig, [signal.SIGTERM])
self.assertEquals(self.sendsig_events, [signal.SIGCHLD, signal.SIGINT,
def testSchedulerCancel(self):
handle = self.mainloop.scheduler.enter(0.1, 1, self._SendSig,
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