Last active
February 22, 2020 15:56
-
-
Save alexnavis/50c81921a17c7998e9cb55af7b428d85 to your computer and use it in GitHub Desktop.
Blog: Python Async
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
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 |
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
# 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