Esempio n. 1
0
 def test_exc_info_no_error(self):
     # Before running
     self.assertFalse(greenlet.Greenlet().exc_info)
     g = greenlet.Greenlet(gevent.sleep)
     g.start()
     g.join()
     self.assertFalse(g.exc_info)
Esempio n. 2
0
    def test_tree_locals(self):
        g = g2 = None

        def func():
            child = greenlet.Greenlet()
            self.assertIs(child.spawn_tree_locals,
                          getcurrent().spawn_tree_locals)
            self.assertIs(child.spawning_greenlet(), getcurrent())

        g = greenlet.Greenlet(func)
        g2 = greenlet.Greenlet(func)
        # Creating those greenlets did not give the main greenlet
        # a locals dict.
        self.assertFalse(hasattr(getcurrent(), 'spawn_tree_locals'),
                         getcurrent())
        self.assertIsNot(g.spawn_tree_locals, g2.spawn_tree_locals)
        g.start()
        g.join()

        raw = gevent.spawn_raw(func)
        self.assertIsNotNone(raw.spawn_tree_locals)
        self.assertIsNot(raw.spawn_tree_locals, g.spawn_tree_locals)
        self.assertIs(raw.spawning_greenlet(), getcurrent())
        while not raw.dead:
            gevent.sleep(0.01)
Esempio n. 3
0
 def test_getframe_value_error(self):
     def get():
         raise ValueError("call stack is not deep enough")
     try:
         ogf = greenlet.sys_getframe
     except AttributeError: # pragma: no cover
         # Must be running cython compiled
         raise unittest.SkipTest("Cannot mock when Cython compiled")
     greenlet.sys_getframe = get
     try:
         child = greenlet.Greenlet()
         self.assertIsNone(child.spawning_stack)
     finally:
         greenlet.sys_getframe = ogf
Esempio n. 4
0
 def func():
     child = greenlet.Greenlet()
     self.assertIs(child.spawn_tree_locals,
                   getcurrent().spawn_tree_locals)
     self.assertIs(child.spawning_greenlet(), getcurrent())