Ejemplo n.º 1
0
 def _test_kill_running(self, block):
     link_test = []
     g = self.hub.spawn(sleep, 10)
     g.rawlink(lambda x: link_test.append(x))
     self._test_kill(g, block=block)
     sleep(0.01)
     assert link_test == [g]
Ejemplo n.º 2
0
 def _test_kill_running(self, block):
     link_test = []
     g = self.hub.spawn(sleep, 10)
     g.rawlink(lambda x: link_test.append(x))
     self._test_kill(g, block=block)
     sleep(0.01)
     assert link_test == [g]
Ejemplo n.º 3
0
 def _test_kill(self, g, block):
     g.kill(block=block)
     if not block:
         sleep(0.01)
     self.assertKilled(g)
     # kill second time must not hurt
     g.kill(block=block)
     self.assertKilled(g)
Ejemplo n.º 4
0
 def _test_kill(self, g, block):
     g.kill(block=block)
     if not block:
         sleep(0.01)
     self.assertKilled(g)
     # kill second time must not hurt
     g.kill(block=block)
     self.assertKilled(g)
Ejemplo n.º 5
0
    def test_simple_exit(self):
        link_test = []

        def waiting_func(seconds, value):
            sleep(seconds)
            print value
            return value

        g = self.hub.Greenlet(waiting_func, 0.01, value=5)
        g.rawlink(lambda x: link_test.append(x))
        assert not g, bool(g)
        assert not g.dead
        assert not g.ready()
        assert not g.successful()
        assert g.value is None
        assert g.exception is None

        g.start()
        assert g  # changed
        assert not g.dead
        assert not g.ready()
        assert not g.successful()
        assert g.value is None
        assert g.exception is None

        sleep(0.001)
        assert g
        assert not g.dead
        assert not g.ready()
        assert not g.successful()
        assert g.value is None
        assert g.exception is None
        assert not link_test

        sleep(0.02)
        assert not g
        assert g.dead
        assert g.ready()
        assert g.successful()
        assert g.value == 5
        assert g.exception is None  # not changed
        assert link_test == [g]  # changed
Ejemplo n.º 6
0
    def test_simple_exit(self):
        link_test = []

        def waiting_func(seconds, value):
            sleep(seconds)
            print value
            return value

        g = self.hub.Greenlet(waiting_func, 0.01, value=5)
        g.rawlink(lambda x: link_test.append(x))
        assert not g, bool(g)
        assert not g.dead
        assert not g.ready()
        assert not g.successful()
        assert g.value is None
        assert g.exception is None

        g.start()
        assert g  # changed
        assert not g.dead
        assert not g.ready()
        assert not g.successful()
        assert g.value is None
        assert g.exception is None

        sleep(0.001)
        assert g
        assert not g.dead
        assert not g.ready()
        assert not g.successful()
        assert g.value is None
        assert g.exception is None
        assert not link_test

        sleep(0.02)
        assert not g
        assert g.dead
        assert g.ready()
        assert g.successful()
        assert g.value == 5
        assert g.exception is None  # not changed
        assert link_test == [g]  # changed
Ejemplo n.º 7
0
    def test_error_exit(self):
        link_test = []

        def func(delay, return_value=4):
            sleep(delay)
            error = ExpectedError("test_error_exit")
            error.myattr = return_value
            raise error

        g = self.hub.Greenlet(func, 0.001, return_value=5)
        g.rawlink(lambda x: link_test.append(x))
        g.start()
        sleep(0.1)
        assert not g
        assert g.dead
        assert g.ready()
        assert not g.successful()
        assert g.value is None  # not changed
        assert g.exception.myattr == 5
        assert link_test == [g], link_test
Ejemplo n.º 8
0
    def test_error_exit(self):
        link_test = []

        def func(delay, return_value=4):
            sleep(delay)
            error = ExpectedError('test_error_exit')
            error.myattr = return_value
            raise error

        g = self.hub.Greenlet(func, 0.001, return_value=5)
        g.rawlink(lambda x: link_test.append(x))
        g.start()
        sleep(0.1)
        assert not g
        assert g.dead
        assert g.ready()
        assert not g.successful()
        assert g.value is None  # not changed
        assert g.exception.myattr == 5
        assert link_test == [g], link_test
Ejemplo n.º 9
0
 def func(delay, return_value=4):
     sleep(delay)
     error = ExpectedError("test_error_exit")
     error.myattr = return_value
     raise error
Ejemplo n.º 10
0
 def waiting_func(seconds, value):
     sleep(seconds)
     print value
     return value
Ejemplo n.º 11
0
 def assertKilled(self, g):
     self._assertKilled(g)
     sleep(0.01)
     self._assertKilled(g)
Ejemplo n.º 12
0
 def func(delay, return_value=4):
     sleep(delay)
     error = ExpectedError('test_error_exit')
     error.myattr = return_value
     raise error
Ejemplo n.º 13
0
 def waiting_func(seconds, value):
     sleep(seconds)
     print value
     return value
Ejemplo n.º 14
0
 def assertKilled(self, g):
     self._assertKilled(g)
     sleep(0.01)
     self._assertKilled(g)