Ejemplo n.º 1
0
 def test_isolation(self):
     local = gruvi.local()
     interleaved = []
     def fiber1():
         local.foo = 10
         interleaved.append(1)
         gruvi.sleep(0)
         self.assertEqual(local.foo, 10)
         local.foo = 30
         interleaved.append(1)
         gruvi.sleep(0)
         self.assertEqual(local.foo, 30)
     def fiber2():
         self.assertFalse(hasattr(local, 'foo'))
         local.foo = 20
         interleaved.append(2)
         gruvi.sleep(0)
         self.assertEqual(local.foo, 20)
         local.foo = 40
         interleaved.append(2)
         gruvi.sleep(0)
         self.assertEqual(local.foo, 40)
     f1 = gruvi.spawn(fiber1)
     f2 = gruvi.spawn(fiber2)
     f1.join(); f2.join()
     self.assertFalse(hasattr(local, 'foo'))
     self.assertEqual(interleaved, [1, 2, 1, 2])
Ejemplo n.º 2
0
 def test_basic(self):
     local = gruvi.local()
     local.foo = 'bar'
     self.assertEqual(local.foo, 'bar')
     del local.foo
     self.assertRaises(AttributeError, local.__getattr__, 'foo')
     self.assertRaises(AttributeError, local.__delattr__, 'foo')
Ejemplo n.º 3
0
 def test_cleanup_on_fiber_exit(self):
     local = gruvi.local()
     def fiber1():
         local.foo = 10
     f1 = gruvi.spawn(fiber1)
     f1.join()
     # Access the local object as if access was from f1
     self.assertIn('foo', local._keys[f1])
     self.assertEqual(local._keys[f1]['foo'], 10)
     del f1; gc.collect()
     self.assertEqual(len(local._keys), 0)
Ejemplo n.º 4
0
 def __init__(self, prefix=None):
     self._prefix = prefix or ''
     self._log = logging.get_logger(self)
     self._init_handlers()
     self._local = gruvi.local()
Ejemplo n.º 5
0
 def __init__(self):
     self._log = logging.get_logger(self)
     self.routes = []
     self._init_mapper()
     self.local = gruvi.local()
Ejemplo n.º 6
0
 def __init__(self):
     self.signal_handlers = []
     self.local = gruvi.local()
     self._init_handlers()