Skip to content

Instantly share code, notes, and snippets.

@djmitche
Created January 5, 2009 03:29
Show Gist options
  • Save djmitche/43251 to your computer and use it in GitHub Desktop.
Save djmitche/43251 to your computer and use it in GitHub Desktop.
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