def test_simple_task(self): maintask = coroutine.getcurrent() def f():pass co = coroutine() co.bind(f) co.switch() assert not co.is_alive assert maintask is coroutine.getcurrent()
def test_is_zombie_del_with_frame(self): try: import _stackless # are we on pypy with a stackless build? except ImportError: skip("only works on pypy-c-stackless") import gc res = [] class MyCoroutine(coroutine): def __del__(self): res.append(self.is_zombie) main = coroutine.getcurrent() def f(): print 'in coro' main.switch() co = MyCoroutine() co.bind(f) co.switch() del co for i in range(10): gc.collect() if res: break co = coroutine() co.bind(f) co.switch() assert res[0], "is_zombie was False in __del__"
def test_backto_main(self): maintask = coroutine.getcurrent() def f(task): task.switch() co = coroutine() co.bind(f,maintask) co.switch()
def test_is_zombie_del_with_frame(self): try: import _stackless # are we on pypy with a stackless build? except ImportError: skip("only works on pypy-c-stackless") import gc res = [] class MyCoroutine(coroutine): def __del__(self): res.append(self.is_zombie) main = coroutine.getcurrent() def f(): print 'in coro' main.switch() co = MyCoroutine() co.bind(f) co.switch() del co for i in range(10): gc.collect() if res: break co = coroutine() co.bind(f) co.switch() assert res[0], "is_zombie was False in __del__"
def test_wrapped_main(self): class mwrap(object): def __init__(self, coro): self._coro = coro def __getattr__(self, attr): return getattr(self._coro, attr) maintask = mwrap(coroutine.getcurrent()) def f(task): task.switch() co = coroutine() co.bind(f,maintask) co.switch()