Ejemplo n.º 1
0
    def fake_setitimer(self, itimer_type, interval):
        """
        Sends a signal to the process after time has passed, according to the
        clock.  Note that this should be a different clock than what is used
        to simulate a hanging process.

        This otherwose follows the API of setitimer exactly with respect to
        which signals are sent based on which timer is used, raising a
        ItimerError when an invalid signal is passed or a negative time
        interval
        """
        if itimer_type == signal.ITIMER_REAL:
            sig = signal.SIGALRM
        elif itimer_type == signal.ITIMER_VIRTUAL:
            sig = signal.SIGVTALRM
        elif itimer_type == signal.ITIMER_PROF:
            sig = signal.SIGPROF
        else:
            # not very helpful, but the error raised by normal setitimer
            raise signal.ItimerError("[Errno 22] Invalid argument")

        if interval < 0:
            raise signal.ItimerError("[Errno 22] Invalid argument")

        def alarm():
            os.kill(os.getpid(), sig)

        self.alarms.append(self.itimer_clock.callLater(interval, alarm))
Ejemplo n.º 2
0
 def sig_vtalrm(self, *args):
     self.hndl_called = True
     if self.hndl_count > 3:
         raise signal.ItimerError(
             "setitimer didn't disable ITIMER_VIRTUAL timer.")
     elif self.hndl_count == 3:
         signal.setitimer(signal.ITIMER_VIRTUAL, 0)
     self.hndl_count += 1
Ejemplo n.º 3
0
    def sig_vtalrm(self, *args):
        self.hndl_called = True

        if self.hndl_count > 3:
            # it shouldn't be here, because it should have been disabled.
            raise signal.ItimerError("setitimer didn't disable ITIMER_VIRTUAL "
                "timer.")
        elif self.hndl_count == 3:
            # disable ITIMER_VIRTUAL, this function shouldn't be called anymore
            signal.setitimer(signal.ITIMER_VIRTUAL, 0)

        self.hndl_count += 1
Ejemplo n.º 4
0
    def sig_vtalrm(self, *args):
        self.hndl_called = True

        if self.hndl_count > 3:
            # it shouldn't be here, because it should have been disabled.
            raise signal.ItimerError("setitimer didn't disable ITIMER_VIRTUAL "
                                     "timer.")
        elif self.hndl_count == 3:
            # disable ITIMER_VIRTUAL, this function shouldn't be called anymore
            signal.setitimer(signal.ITIMER_VIRTUAL, 0)
            if test_support.verbose:
                print("last SIGVTALRM handler call")

        self.hndl_count += 1

        if test_support.verbose:
            print("SIGVTALRM handler invoked", args)