コード例 #1
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 def fmain(seen):
     try:
         greenlet.getcurrent().parent.switch()
     except:
         seen.append(sys.exc_info()[0])
         raise
     raise ValueError
コード例 #2
0
 def fmain(seen):
     try:
         greenlet.getcurrent().parent.switch()
     except:
         seen.append(sys.exc_info()[0])
         raise
     raise ValueError
コード例 #3
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 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)
コード例 #4
0
 def next(self):
     self.parent = greenlet.getcurrent()
     result = self.switch()
     if self:
         return result
     else:
         raise StopIteration
コード例 #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)
コード例 #6
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 def next(self):
     self.parent = greenlet.getcurrent()
     result = self.switch()
     if self:
         return result
     else:
         raise StopIteration
コード例 #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
コード例 #8
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 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
コード例 #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
コード例 #10
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
    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
コード例 #11
0
ファイル: stackless.py プロジェクト: antoine1fr/pygirl
        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
コード例 #12
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 def f1():
     f = sys._getframe(0)
     assert f.f_back is None
     greenlet.getcurrent().parent.switch(f)
     return "meaning of life"
コード例 #13
0
 def f():
     lst.append(1)
     greenlet.getcurrent().parent.switch()
     lst.append(3)
コード例 #14
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 def switch(*args):
     return greenlet.getcurrent().parent.switch(*args)
コード例 #15
0
 def switch(*args):
     return greenlet.getcurrent().parent.switch(*args)
コード例 #16
0
 def f1():
     f = sys._getframe(0)
     assert f.f_back is None
     greenlet.getcurrent().parent.switch(f)
     return "meaning of life"
コード例 #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
コード例 #18
0
ファイル: test_greenlet.py プロジェクト: gorakhargosh/pypy
 def f():
     lst.append(1)
     greenlet.getcurrent().parent.switch()
     lst.append(3)
コード例 #19
0
 def getcurrent():
     """coroutine.getcurrent() -> the currently running coroutine"""
     try:
         return greenlet.getcurrent().coro
     except AttributeError:
         return _maincoro
コード例 #20
0
ファイル: stackless.py プロジェクト: antoine1fr/pygirl
 def getcurrent():
     """coroutine.getcurrent() -> the currently running coroutine"""
     try:
         return greenlet.getcurrent().coro
     except AttributeError:
         return _maincoro