def threader(self, thread_id): """ Worker function. :return: :param thread_id: Assigned ID of thread. """ while not self.task_queue.empty(): # While there are any tasks task = self.task_queue.get() # Get one of them if task['n_errors'] >= self.max_allowed_errors: # Too many errors print_util.print_warning( '{0} --> Too many errors in task {1}. Skipping.'.format( thread_id, task)) continue print_util.print_info('{0} --> New task : {1}'.format( thread_id, task)) # Log the task try: # Call corresponding function if task['type'] == 0: self.get_movies(thread_id, task['url']) elif task['type'] == 1: self.download_movie(thread_id, task['url'], task['movie']) elif task['type'] == 2: self.download_song(thread_id, task['url'], task['song'], task['movie'], task['movie_url']) print_util.print_info('{0} --> Task complete : {1}'.format( thread_id, task), Colors.GREEN) # Log success except Exception as e: # Some error print_util.print_error('{0} --> Error : {1}'.format( thread_id, e)) # Log it task['n_errors'] += 1 # Increment number of errors self.task_queue.put(task) # Put back in queue
def threader(self, thread_id): """ Worker function :param thread_id: Ass usual """ while not self.task_queue.empty(): task = self.task_queue.get() if task['n_errors'] >= self.max_allowed_errors: print_util.print_warning( '{0} --> Too many errors in task {1}. Skipping.'.format( thread_id, task)) continue print_util.print_info('{0} --> New task : {1}'.format( thread_id, task)) try: if task['type'] == 0: self.get_artists(thread_id, task['url']) elif task['type'] == 1: self.get_artist(thread_id, task['url'], task['artist']) elif task['type'] == 2: self.get_songs_from_page(thread_id, task['url'], task['artist']) elif task['type'] == 3: self.get_song(thread_id, task['url'], task['song'], task['artist']) print_util.print_info( '{0} --> Task complete : {1}'.format(thread_id, task), Colors.GREEN) except Exception as e: print_util.print_error('{0} --> Error : {1}'.format( thread_id, e)) task['n_errors'] += 1 self.task_queue.put(task)
def threader(self, thread_id): """ Worker function :param thread_id: Ass usual """ while not self.task_queue.empty(): task = self.task_queue.get() if task['n_errors'] >= self.max_allowed_errors: print_util.print_warning( '{0} --> Too many errors in task {1}. Skipping.'.format( thread_id, task ) ) continue print_util.print_info( '{0} --> New task : {1}'.format( thread_id, task ) ) try: if task['type'] == 0: self.get_artists( thread_id, task['url'] ) elif task['type'] == 1: self.get_artist( thread_id, task['url'], task['artist'] ) elif task['type'] == 2: self.get_songs_from_page( thread_id, task['url'], task['artist'] ) elif task['type'] == 3: self.get_song( thread_id, task['url'], task['song'], task['artist'] ) print_util.print_info( '{0} --> Task complete : {1}'.format( thread_id, task ), Colors.GREEN ) except Exception as e: print_util.print_error( '{0} --> Error : {1}'.format( thread_id, e ) ) task['n_errors'] += 1 self.task_queue.put(task)
def threader(self, thread_id): """ Worker function. :return: :param thread_id: Assigned ID of thread. """ while not self.task_queue.empty(): # While there are any tasks task = self.task_queue.get() # Get one of them if task['n_errors'] >= self.max_allowed_errors: # Too many errors print_util.print_warning( '{0} --> Too many errors in task {1}. Skipping.'.format( thread_id, task ) ) continue print_util.print_info( '{0} --> New task : {1}'.format( thread_id, task ) ) # Log the task try: # Call corresponding function if task['type'] == 0: self.get_movies( thread_id, task['url'] ) elif task['type'] == 1: self.download_movie( thread_id, task['url'], task['movie'] ) elif task['type'] == 2: self.download_song( thread_id, task['url'], task['song'], task['movie'], task['movie_url'] ) print_util.print_info( '{0} --> Task complete : {1}'.format( thread_id, task ), Colors.GREEN ) # Log success except Exception as e: # Some error print_util.print_error( '{0} --> Error : {1}'.format( thread_id, e ) ) # Log it task['n_errors'] += 1 # Increment number of errors self.task_queue.put(task) # Put back in queue