Skip to content

Instantly share code, notes, and snippets.

@alexnavis
Last active February 22, 2020 15:56
Show Gist options
  • Save alexnavis/50c81921a17c7998e9cb55af7b428d85 to your computer and use it in GitHub Desktop.
Save alexnavis/50c81921a17c7998e9cb55af7b428d85 to your computer and use it in GitHub Desktop.
Blog: Python Async
import random
def magic_pot(start=1, end=1000):
while True:
stop = (yield random.randint(start, end))
if stop is True:
print("magicpot stopped")
break
# gen = magic_pot()
# print(gen.__next__()) # 702
# print(gen.__next__()) # 401
# print(gen.__next__()) # 902
# try:
# gen.send(True) # stopped
# except StopIteration:
# print('iteration stopped')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment