Example #1
0
        def test_get_timer_recursive(self):
            """
            If a function acquires a countdown timer with default scope,
            then recursive calls to the function should re-acquire the
            timer rather than creating a new one. That is only the last
            recursive call's timer will take effect.
            """
            self.server.start()
            timer.configure(timer.LocalTimerClient(self.mp_queue))

            # func should not time out
            def func(n):
                if n > 0:
                    with timer.expires(after=0.1):
                        func(n - 1)
                        time.sleep(0.05)

            func(4)

            # func2 should time out
            def func2(n):
                if n > 0:
                    with timer.expires(after=0.1):
                        func2(n - 1)
                        time.sleep(0.2)

            p = mp.Process(target=func2, args=(2,))
            p.start()
            p.join()
            self.assertEqual(-signal.SIGKILL, p.exitcode)
Example #2
0
 def func2(n, mp_queue):
     if mp_queue is not None:
         timer.configure(timer.LocalTimerClient(mp_queue))
     if n > 0:
         with timer.expires(after=0.1):
             func2(n - 1, None)
             time.sleep(0.2)
Example #3
0
        def _run(mp_queue, timeout, duration):
            client = timer.LocalTimerClient(mp_queue)
            timer.configure(client)

            with timer.expires(after=timeout):
                time.sleep(duration)
Example #4
0
 def test_happy_path(self):
     timer.configure(timer.LocalTimerClient(self.mp_queue))
     with timer.expires(after=0.5):
         time.sleep(0.1)
Example #5
0
 def test_no_client(self):
     # no timer client configured; exception expected
     timer.configure(None)
     with self.assertRaises(RuntimeError):
         with timer.expires(after=1):
             pass
Example #6
0
def _stuck_function(rank, mp_queue):
    timer.configure(timer.LocalTimerClient(mp_queue))
    with timer.expires(after=1):
        time.sleep(5)