def searcher():
print("entered into searcher()")
import time
#some time consuming task
book="this book is about a famous software developer mr.N.Harish"
time.sleep(3)
while True:
text=(yield) #this means i want use this function 'searcher' as coroutine. now it is not a function it is coroutine
print("started using function 'searcher' as coroutine ")
if text in book:
print("text is in the book")
else:
print("text is not in the book")
search=searcher() #instance of searcher coroutine
print("search started")
if __name__=='__main__':
next(search) #start coroutine from text=(yield)
print("next method run")
search.send("software harish")#send values to coroutine
input("enter any key:")
search.send("Harish")
print(type(search))
search.close() #after this you cannot send any value
Comments
Post a Comment