Last active
December 11, 2015 09:59
-
-
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
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 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