+ def set_signal(self, signum, sighandler):
+ prev = self.signals.get(signum, None)
+ # If the signal was not already handled, handle it
+ if signum not in self.signals:
+ signal.signal(signum, signal_handler)
+ self.signals[signum] = sighandler
+ return prev
+
+ def get_signal_handler(self, signum):
+ return self.signals[signum]
+
+ def unset_signal(self, signum):
+ prev = self.signals[signum]
+ # Restore the default handler
+ signal.signal(signum, signal.SIG_DFL)
+ return prev
+