예제 #1
0
def test_sleep():
    coro.print_stderr('    This pause should be 1 second.\n')
    coro.sleep_relative(1)
    coro.print_stderr('    This pause should be 1 second.\n')
    coro.sleep_relative(1.0)
    coro.print_stderr('    This pause should be 1 second.\n')
    coro.sleep_relative(1L * coro.ticks_per_sec)
    coro.print_stderr('    This pause should be 1 second.\n')
    coro.sleep_absolute(coro.now + 1L * coro.ticks_per_sec)
예제 #2
0
    def test_scheduled_staging_interrupt(self):
        """Test interrupting a thread that is scheduled and in the staging list."""
        t = coro.get_now() + coro.ticks_per_sec*3
        exception_raised = [False]
        def foo():
            self.assertFalse(exception_raised[0])
            try:
                coro.sleep_absolute(t)
            except TestException:
                exception_raised[0] = True

        c = coro.spawn(foo)
        coro.sleep_absolute(t)
        c.raise_exception(TestException)
        coro.yield_slice()
        self.assertTrue(exception_raised[0])
예제 #3
0
    def test_scheduled_staging_interrupt(self):
        """Test interrupting a thread that is scheduled and in the staging list."""
        t = coro.get_now() + coro.ticks_per_sec * 3
        exception_raised = [False]

        def foo():
            self.assertFalse(exception_raised[0])
            try:
                coro.sleep_absolute(t)
            except TestException:
                exception_raised[0] = True

        c = coro.spawn(foo)
        coro.sleep_absolute(t)
        c.raise_exception(TestException)
        coro.yield_slice()
        self.assertTrue(exception_raised[0])
예제 #4
0
 def foo():
     self.assertFalse(exception_raised[0])
     try:
         coro.sleep_absolute(t)
     except TestException:
         exception_raised[0] = True
예제 #5
0
 def foo():
     self.assertFalse(exception_raised[0])
     try:
         coro.sleep_absolute(t)
     except TestException:
         exception_raised[0] = True