Exemplo n.º 1
0
 def test_throw_GreenletExit_not_started(self):
     import greenlet
     def f():
         never_executed
     g = greenlet.greenlet(f)
     e = greenlet.GreenletExit()
     x = g.throw(e)
     assert x is e
Exemplo n.º 2
0
 def test_throw_GreenletExit_not_started(self):
     import greenlet
     def f():
         never_executed
     g = greenlet.greenlet(f)
     e = greenlet.GreenletExit()
     x = g.throw(e)
     assert x is e
Exemplo n.º 3
0
 def test_kwargs_to_f(self):
     import greenlet
     seen = []
     def f(*args, **kwds):
         seen.append([args, kwds])
     g = greenlet.greenlet(f)
     g.switch(1, 2, x=3, y=4)
     assert seen == [[(1, 2), {'x': 3, 'y': 4}]]
Exemplo n.º 4
0
 def test_kwargs_to_f(self):
     import greenlet
     seen = []
     def f(*args, **kwds):
         seen.append([args, kwds])
     g = greenlet.greenlet(f)
     g.switch(1, 2, x=3, y=4)
     assert seen == [[(1, 2), {'x': 3, 'y': 4}]]
Exemplo n.º 5
0
 def test_throw_GreenletExit_already_finished(self):
     import greenlet
     def f():
         pass
     g = greenlet.greenlet(f)
     g.switch()
     e = greenlet.GreenletExit()
     x = g.throw(e)
     assert x is e
Exemplo n.º 6
0
 def test_throw_GreenletExit_already_finished(self):
     import greenlet
     def f():
         pass
     g = greenlet.greenlet(f)
     g.switch()
     e = greenlet.GreenletExit()
     x = g.throw(e)
     assert x is e
Exemplo n.º 7
0
 def test_throw_exception_already_finished(self):
     import greenlet
     def f():
         pass
     g = greenlet.greenlet(f)
     g.switch()
     seen = []
     class MyException(Exception):
         def __init__(self):
             seen.append(1)
     try:
         g.throw(MyException)
     except MyException:
         pass
     else:
         raise AssertionError("no exception??")
     assert seen == [1]
Exemplo n.º 8
0
 def test_throw_exception_already_finished(self):
     import greenlet
     def f():
         pass
     g = greenlet.greenlet(f)
     g.switch()
     seen = []
     class MyException(Exception):
         def __init__(self):
             seen.append(1)
     try:
         g.throw(MyException)
     except MyException:
         pass
     else:
         raise AssertionError("no exception??")
     assert seen == [1]
Exemplo n.º 9
0
gr1.switch()

import greenlet


def test1(x, y):
    z = gr2.switch(x + y)  # jump into test2
    print("test1 ", z)


def test2(u):
    print("test2 ", u)
    gr1.switch(10)  # z = 10


gr1 = greenlet.greenlet(test1)
gr2 = greenlet.greenlet(test2)
print(gr1.switch("hello", " world"))  # jump into test1

## test2  hello world
## test1  10
## None

import greenlet


def test1(x, y):
    print(id(greenlet.getcurrent()),
          id(greenlet.getcurrent().parent))  # 40240272 40239952
    z = gr2.switch(x + y)
    print("back z", z)  # 这里没有输出
Exemplo n.º 10
0
from greenlet import greenlet


def test1():
    print(12)
    gr2.switch()
    print(34)


def test2():
    print(56)
    gr1.switch()
    print(78)


# 协程对象
gr1 = greenlet.greenlet(test1)
gr2 = greenlet.greenlet(test2)
gr1.switch()