co-routine은 해당 function의 실행환경을 보관하고 있으며
이를 이용하여 generator를 작성한다.
def coroutine():
print("A ...")
while True:
print("B ...")
msg = yield
print("Hello, your input message is '%s'" % msg)
def main():
print("1 ---")
c = coroutine()
print("2 ---")
next(c)
print("3 ---")
next(c)
print("4 ---")
c.send("Test")
print("5 ---")
c.send("Coroutine")
print("6 ---")
if __name__ == "__main__":
main()
댓글 없음:
댓글 쓰기