Coroutines

 


def searcher():

    import time

    # Some 4 seconds time consuming task

    book = "This is a book on harry and code with harry and good"

    time.sleep(4)


    while True:

        text = (yield)

        if text in book:

            print("Your text is in the book")

        else:

            print("Text is not in the book")


search = searcher()

print("search started")

next(search)

print("Next method run")

search.send("harry")


search.close()


Comments

Popular posts from this blog

Practice Execise 3

Pickle Module