Created
June 11, 2020 07:06
-
-
Save velotiotech/e682576969d9bd9f102282e9a40fcec4 to your computer and use it in GitHub Desktop.
coroutines in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_name(prefix): | |
print("Searching prefix:{}".format(prefix)) | |
try : | |
while True: | |
# yeild used to create coroutine | |
name = (yield) | |
if prefix in name: | |
print(name) | |
except GeneratorExit: | |
print("Closing coroutine!!") | |
corou = print_name("Dear") | |
corou.__next__() | |
corou.send("James") | |
corou.send("Dear James") | |
corou.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment