Пример #1
0
 def Catcher(do_switch):
   assert do_switch is True
   try:
     gc.switch('catcher')
     items.append('ok')
   except BaseException, e:
     items.append(type(e))
Пример #2
0
 def Catcher(do_switch):
     assert do_switch is True
     try:
         gc.switch('catcher')
         items.append('ok')
     except BaseException, e:
         items.append(type(e))
Пример #3
0
        def testSwitchValue(self):
            gc = self.greenlet.getcurrent()
            self.assertEqual('self0', gc.switch('self0'))
            self.assertEqual((),
                             gc.switch())  # The default is the empty tuple.
            next = {}
            items = []

            def Switcher(name):
                if name == 'g2':
                    items.append(gc.switch())
                else:
                    items.append(gc.switch(name))
                items.append(next[name].switch('+' + name))

            g1 = self.greenlet(lambda: Switcher('g1'))
            g2 = self.greenlet(lambda: Switcher('g2'))
            g3 = self.greenlet(lambda: Switcher('g3'))
            next['g1'] = g2
            next['g2'] = g3
            next['g3'] = gc
            assert not (g1 or g1.dead)
            assert not (g2 or g2.dead)
            assert not (g3 or g3.dead)
            self.assertEqual('self1', gc.switch('self1'))
            self.assertEqual('g1', g1.switch())
            self.assertEqual((), g2.switch())
            self.assertEqual('g3', g3.switch())
            self.assertEqual('self2', gc.switch('self2'))
            self.assertEqual([], items)
            assert g1 and not g1.dead
            assert g2 and not g2.dead
            assert g3 and not g3.dead
            self.assertEqual('+g3', g1.switch('base'))
            self.assertEqual(['base', '+g1', '+g2'], items)
            assert g1 and not g1.dead
            assert g2 and not g2.dead
            assert g3 and not g3.dead
            self.assertEqual(None, g3.switch('d3'))
            assert not g3 and g3.dead
            self.assertEqual(['base', '+g1', '+g2', 'd3'], items)
            self.assertEqual(None, g2.switch('d2'))
            assert not g2 and g2.dead
            self.assertEqual(['base', '+g1', '+g2', 'd3', 'd2'], items)
            self.assertEqual(None, g1.switch('d1'))
            assert not g1 and g1.dead
            self.assertEqual(['base', '+g1', '+g2', 'd3', 'd2', 'd1'], items)
Пример #4
0
 def testSwitchValue(self):
   gc = self.greenlet.getcurrent()
   self.assertEqual('self0', gc.switch('self0'))
   self.assertEqual((), gc.switch())  # The default is the empty tuple.
   next = {}
   items = []
   def Switcher(name):
     if name == 'g2':
       items.append(gc.switch())
     else:
       items.append(gc.switch(name))
     items.append(next[name].switch('+' + name))
   g1 = self.greenlet(lambda: Switcher('g1'))
   g2 = self.greenlet(lambda: Switcher('g2'))
   g3 = self.greenlet(lambda: Switcher('g3'))
   next['g1'] = g2
   next['g2'] = g3
   next['g3'] = gc
   assert not (g1 or g1.dead)
   assert not (g2 or g2.dead)
   assert not (g3 or g3.dead)
   self.assertEqual('self1', gc.switch('self1'))
   self.assertEqual('g1', g1.switch())
   self.assertEqual((),   g2.switch())
   self.assertEqual('g3', g3.switch())
   self.assertEqual('self2', gc.switch('self2'))
   self.assertEqual([], items)
   assert g1 and not g1.dead
   assert g2 and not g2.dead
   assert g3 and not g3.dead
   self.assertEqual('+g3', g1.switch('base'))
   self.assertEqual(['base', '+g1', '+g2'], items)
   assert g1 and not g1.dead
   assert g2 and not g2.dead
   assert g3 and not g3.dead
   self.assertEqual(None, g3.switch('d3'))
   assert not g3 and g3.dead
   self.assertEqual(['base', '+g1', '+g2', 'd3'], items)
   self.assertEqual(None, g2.switch('d2'))
   assert not g2 and g2.dead
   self.assertEqual(['base', '+g1', '+g2', 'd3', 'd2'], items)
   self.assertEqual(None, g1.switch('d1'))
   assert not g1 and g1.dead
   self.assertEqual(['base', '+g1', '+g2', 'd3', 'd2', 'd1'], items)
Пример #5
0
 def Switcher(name):
   if name == 'g2':
     items.append(gc.switch())
   else:
     items.append(gc.switch(name))
   items.append(next[name].switch('+' + name))
Пример #6
0
 def Switcher(name):
     if name == 'g2':
         items.append(gc.switch())
     else:
         items.append(gc.switch(name))
     items.append(next[name].switch('+' + name))