Skip to content

Instantly share code, notes, and snippets.

@jcrubino
Last active December 11, 2015 09:59
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 jcrubino/4583714 to your computer and use it in GitHub Desktop.
Save jcrubino/4583714 to your computer and use it in GitHub Desktop.
example of using gevent coroutines inside a function. Uses pylast and gevent for network calls to last.fm
def define_fan(fan):
pool = Pool(4)
try:
book = {}
def name(fan):
book['name'] = fan.item.get_name()
def get_age(fan):
book['age'] = fan.item.get_age()
def get_gender(fan):
book['gender'] = fan.item.get_gender()
def get_top_artists(fan):
book['top_artists'] = fan.item.get_top_artists()
stage = pool.map(lambda x: x(fan), [name, get_age, get_gender, get_top_artists]) # lint:ok
book['top_artists'] = [(x.item.name, int(x.weight)) for x in book['top_artists']] # lint:ok
except Exception as e:
print e.message, 'define_fan'
return book
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment