Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/e682576969d9bd9f102282e9a40fcec4 to your computer and use it in GitHub Desktop.
Save velotiotech/e682576969d9bd9f102282e9a40fcec4 to your computer and use it in GitHub Desktop.
coroutines in python
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