2018년 8월 13일 월요일

Co-Routine


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()

댓글 없음:

댓글 쓰기

200926.가오리코스 라이딩

9/26 골절인지 아닌지 확인 안됨. 이후 미세골절여부 확인 핸드폰을 드는 것도 어려움 9/29 x ray 다시 찍지 않고 이후 재 방문 요청 ...