Beispiel #1
0
 def fmain(seen):
     try:
         greenlet.getcurrent().parent.switch()
     except:
         seen.append(sys.exc_info()[0])
         raise
     raise ValueError
Beispiel #2
0
 def fmain(seen):
     try:
         greenlet.getcurrent().parent.switch()
     except:
         seen.append(sys.exc_info()[0])
         raise
     raise ValueError
Beispiel #3
0
 def Yield(value):
     g = greenlet.getcurrent()
     while not isinstance(g, genlet):
         if g is None:
             raise RuntimeError, 'yield outside a genlet'
         g = g.parent
     g.parent.switch(value)
Beispiel #4
0
 def next(self):
     self.parent = greenlet.getcurrent()
     result = self.switch()
     if self:
         return result
     else:
         raise StopIteration
Beispiel #5
0
 def Yield(value):
     g = greenlet.getcurrent()
     while not isinstance(g, genlet):
         if g is None:
             raise RuntimeError, 'yield outside a genlet'
         g = g.parent
     g.parent.switch(value)
Beispiel #6
0
 def next(self):
     self.parent = greenlet.getcurrent()
     result = self.switch()
     if self:
         return result
     else:
         raise StopIteration
Beispiel #7
0
 def test_switch_back_to_main(self):
     from _stackless import greenlet
     lst = []
     main = greenlet.getcurrent()
     def f(x):
         lst.append(x)
         x = main.switch(x + 10)
         return 40 + x 
     g = greenlet(f)
     res = g.switch(20)
     assert res == 30
     assert lst == [20]
     assert not g.dead
     res = g.switch(2)
     assert res == 42
     assert g.dead
Beispiel #8
0
 def test_switch_back_to_main(self):
     from _stackless import greenlet
     lst = []
     main = greenlet.getcurrent()
     def f(x):
         lst.append(x)
         x = main.switch(x + 10)
         return 40 + x 
     g = greenlet(f)
     res = g.switch(20)
     assert res == 30
     assert lst == [20]
     assert not g.dead
     res = g.switch(2)
     assert res == 42
     assert g.dead
Beispiel #9
0
    def test_throw_goes_to_original_parent(self):
        from _stackless import greenlet
        main = greenlet.getcurrent()

        def f1():
            try:
                main.switch("f1 ready to catch")
            except IndexError:
                return "caught"
            else:
                return "normal exit"

        def f2():
            main.switch("from f2")

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        raises(IndexError, g2.throw, IndexError)
        assert g2.dead
        assert g1.dead

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        res = g1.switch()
        assert res == "f1 ready to catch"
        res = g2.throw(IndexError)
        assert res == "caught"
        assert g2.dead
        assert g1.dead

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        res = g1.switch()
        assert res == "f1 ready to catch"
        res = g2.switch()
        assert res == "from f2"
        res = g2.throw(IndexError)
        assert res == "caught"
        assert g2.dead
        assert g1.dead
Beispiel #10
0
    def test_throw_goes_to_original_parent(self):
        from _stackless import greenlet
        main = greenlet.getcurrent()
        def f1():
            try:
                main.switch("f1 ready to catch")
            except IndexError:
                return "caught"
            else:
                return "normal exit"
        def f2():
            main.switch("from f2")

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        raises(IndexError, g2.throw, IndexError)
        assert g2.dead
        assert g1.dead

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        res = g1.switch()
        assert res == "f1 ready to catch"
        res = g2.throw(IndexError)
        assert res == "caught"
        assert g2.dead
        assert g1.dead

        g1 = greenlet(f1)
        g2 = greenlet(f2, parent=g1)
        res = g1.switch()
        assert res == "f1 ready to catch"
        res = g2.switch()
        assert res == "from f2"
        res = g2.throw(IndexError)
        assert res == "caught"
        assert g2.dead
        assert g1.dead
Beispiel #11
0
        is_alive = property(_is_alive)
        del _is_alive

        def getcurrent():
            """coroutine.getcurrent() -> the currently running coroutine"""
            try:
                return greenlet.getcurrent().coro
            except AttributeError:
                return _maincoro
        getcurrent = staticmethod(getcurrent)

        def __reduce__(self):
            raise TypeError, 'pickling is not possible based upon greenlets'

    _maincoro = coroutine()
    maingreenlet = greenlet.getcurrent()
    _maincoro._frame = frame = MWrap(maingreenlet)
    frame.coro = _maincoro
    del frame
    del maingreenlet

from collections import deque

import operator
__all__ = 'run getcurrent getmain schedule tasklet channel coroutine \
                TaskletExit greenlet'.split()

_global_task_id = 0
_squeue = None
_main_tasklet = None
_main_coroutine = None
Beispiel #12
0
 def f1():
     f = sys._getframe(0)
     assert f.f_back is None
     greenlet.getcurrent().parent.switch(f)
     return "meaning of life"
Beispiel #13
0
 def f():
     lst.append(1)
     greenlet.getcurrent().parent.switch()
     lst.append(3)
Beispiel #14
0
 def switch(*args):
     return greenlet.getcurrent().parent.switch(*args)
Beispiel #15
0
 def switch(*args):
     return greenlet.getcurrent().parent.switch(*args)
Beispiel #16
0
 def f1():
     f = sys._getframe(0)
     assert f.f_back is None
     greenlet.getcurrent().parent.switch(f)
     return "meaning of life"
Beispiel #17
0
        del _is_alive

        def getcurrent():
            """coroutine.getcurrent() -> the currently running coroutine"""
            try:
                return greenlet.getcurrent().coro
            except AttributeError:
                return _maincoro

        getcurrent = staticmethod(getcurrent)

        def __reduce__(self):
            raise TypeError, 'pickling is not possible based upon greenlets'

    _maincoro = coroutine()
    maingreenlet = greenlet.getcurrent()
    _maincoro._frame = frame = MWrap(maingreenlet)
    frame.coro = _maincoro
    del frame
    del maingreenlet

from collections import deque

import operator

__all__ = 'run getcurrent getmain schedule tasklet channel coroutine \
                TaskletExit greenlet'.split()

_global_task_id = 0
_squeue = None
_main_tasklet = None
Beispiel #18
0
 def f():
     lst.append(1)
     greenlet.getcurrent().parent.switch()
     lst.append(3)
Beispiel #19
0
 def getcurrent():
     """coroutine.getcurrent() -> the currently running coroutine"""
     try:
         return greenlet.getcurrent().coro
     except AttributeError:
         return _maincoro
Beispiel #20
0
 def getcurrent():
     """coroutine.getcurrent() -> the currently running coroutine"""
     try:
         return greenlet.getcurrent().coro
     except AttributeError:
         return _maincoro