Created
January 5, 2009 03:29
-
-
Save djmitche/43251 to your computer and use it in GitHub Desktop.
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 ping(host): | |
ip = yield hostname_lookup(host) | |
pingrate = (yield ping_ip(ip)) | |
raise StopIteration(pingrate) # uthreaded equivalent of "return" | |
## incorrect | |
def multiping(hosts): | |
for host in hosts: | |
ping(host) | |
## correct | |
def multiping(hosts): | |
for host in hosts: | |
yield ping(host) | |
# I realize this is a fairly contrived example! | |
# Question: how can I help detect programmer errors like this, where a generator function is called and | |
# the generator is immediately discarded? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment