'The callback for when a task of a bear completes. It is responsible for
checking if the bear completed its execution and the handling of the
result generated by the task. It also schedules new tasks if
dependencies get resolved.
:param bear:
The bear that the task belongs to.
:param task:
The task that completed.'

def _finish_task(self, bear, task):

    try:
        results = task.result()
        for dependant in self.dependency_tracker.get_dependants(bear):
            dependant.dependency_results[type(bear)] += results
    except Exception as ex:
        logging.error('An    exception    was    thrown    during    bear    execution.', exc_info=ex)
        results = None
        dependants = self.dependency_tracker.get_all_dependants(bear)
        for dependant in dependants:
            self.dependency_tracker.resolve(dependant)
        logging.debug(('Following    dependent    bears    were    unscheduled:    ' + ',    '.join((repr(dependant) for dependant in dependants))))
    finally:
        self.running_tasks[bear].remove(task)
        self._cleanup_bear(bear)
    if (results is not None):
        for result in results:
            try:
                self.result_callback(result)
            except Exception as ex:
                logging.error('An    exception    was    thrown    during    result-handling.', exc_info=ex)
