def test_returnOldFD(self): """ L{installHandler} returns the previously registered file descriptor. """ read, write = self.pipe() oldFD = installHandler(write) self.assertEqual(installHandler(oldFD), write)
def test_uninstallHandler(self): """ C{installHandler(-1)} removes the SIGCHLD handler completely. """ read, write = self.pipe() self.assertTrue(isDefaultHandler()) installHandler(write) self.assertFalse(isDefaultHandler()) installHandler(-1) self.assertTrue(isDefaultHandler())
def tearDown(self): """ Restore whatever signal handler was present when setUp ran. """ # If tests set up any kind of handlers, clear them out. installHandler(-1) signal.signal(signal.SIGCHLD, signal.SIG_DFL) # Now restore whatever the setup was before the test ran. if self.signalModuleHandler is not None: signal.signal(signal.SIGCHLD, self.signalModuleHandler) elif self.oldFD != -1: installHandler(self.oldFD)
def test_installHandler(self): """ The file descriptor passed to L{installHandler} has a byte written to it when SIGCHLD is delivered to the process. """ read, write = self.pipe() installHandler(write) exc = self.assertRaises(OSError, os.read, read, 1) self.assertEqual(exc.errno, errno.EAGAIN) os.kill(os.getpid(), signal.SIGCHLD) self.assertEqual(len(os.read(read, 5)), 1)
def setUp(self): """ Save the current SIGCHLD handler as reported by L{signal.signal} and the current file descriptor registered with L{installHandler}. """ handler = signal.getsignal(signal.SIGCHLD) if handler != signal.SIG_DFL: self.signalModuleHandler = handler signal.signal(signal.SIGCHLD, signal.SIG_DFL) else: self.signalModuleHandler = None self.oldFD = installHandler(-1) if self.signalModuleHandler is not None and self.oldFD != -1: msg("Previous test didn't clean up after its SIGCHLD setup: %r %r" % (self.signalModuleHandler, self.oldFD))
def setUp(self): """ Save the current SIGCHLD handler as reported by L{signal.signal} and the current file descriptor registered with L{installHandler}. """ handler = signal.getsignal(signal.SIGCHLD) if handler != signal.SIG_DFL: self.signalModuleHandler = handler signal.signal(signal.SIGCHLD, signal.SIG_DFL) else: self.signalModuleHandler = None self.oldFD = installHandler(-1) if self.signalModuleHandler is not None and self.oldFD != -1: msg("SIGCHLD setup issue: %r %r" % (self.signalModuleHandler, self.oldFD)) raise RuntimeError("You used some signal APIs wrong! Try again.")
def uninstall(self): """ Remove the handler which makes this waker active. """ _signals.installHandler(-1)
def install(self): """ Install the handler necessary to make this waker active. """ _signals.installHandler(self.o)