python/coroutin3.py


def coro(cArg):
    print(f"coro{cArg} 0 start cArg={cArg}")
    y = yield f"coro{cArg} 1 yield"
    print(f"coro{cArg} 2 yield got {y}")
    y = yield f"coro{cArg} 3 got {y} yield"
    print(f"coro{cArg} 4 yield got {y}")
    print(f"coro{cArg} 5 stopping")

def work(): 
    print("work 0")
    c = coro("w1call")
    print("work 1 coro(...)=", repr(c))
    print("work 2 next(coro)", next(c))
    print("work 3 send(worksend3)", c.send("worksend3"));
    try:
        print("work 4 next(coro)", next(c))
    except BaseException as e:
        print("work 4 next(coro) exception", repr(e))
    print("work 6 coro=", repr(c))

work()
import dis
print("***** dis(coro)")
dis.dis(coro)
print("***** dis(work)")
dis.dis(work)