Skip to content

Instantly share code, notes, and snippets.

@robrocker7
Created January 22, 2013 19:59
Show Gist options
  • Save robrocker7/4597910 to your computer and use it in GitHub Desktop.
Save robrocker7/4597910 to your computer and use it in GitHub Desktop.
class DataCell(object):
def __init__(self, data):
self.data = data
def set(self, val):
self.data = val
def get(self):
return self.data
def playlist_worker(profile, station, data):
logging.debug('start playlist worker')
data.set(station.get_playlist(profile, limit=20, offset=0))
logging.debug('end playlist worker')
def artist_worker(profile, station, data):
logging.debug('start artist worker')
data.set(station.get_artists(profile, limit=20, offset=0))
logging.debug('end artist worker')
def publish_worker(request, fid, data):
logging.debug('start publish worker')
obj = {}
obj['can_publish'] = False
obj['customizations'] = []
try:
stationProfile = StationProfile(request.user, fid)
#logging.debug('stationView: station profile view end')
#logging.debug('stationView: station profile can publish start')
obj['can_publish'] = stationProfile.can_publish()
#logging.debug('stationView: station profile can publish end')
#logging.debug('stationView: station profile customizations start')
obj['customizations'] = stationProfile.get_customizations()
except:
pass
data.set(obj)
logging.debug('end publish worker')
artists = DataCell([])
tracks = DataCell([])
customizations = DataCell({})
tasks = (
(artist_worker, (profile, station, artists)),
(playlist_worker, (profile, station, tracks)),
(publish_worker, (request, fid, customizations)),
)
threads = []
logging.debug('start threading')
for task in tasks:
t = threading.Thread(target=task[0], args=(task[1]))
threads.append(t)
t.setDaemon(True)
t.start()
main_thread = threading.currentThread()
for t in threads:
if t is main_thread:
continue
logging.debug('joining %s', t.getName())
t.join()
logging.debug('end threading')
obj['artists'] = artists.get()
obj['songs'] = tracks.get()
obj['can_publish'] = customizations.get()['can_publish']
obj['customizations'] = customizations.get()['customizations']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment