'Cleans up state of an ongoing run for a bear.
- If the given bear has no running tasks left:
- Resolves its dependencies.
- Schedules dependant bears.
- Removes the bear from the ``running_tasks`` dict.
- Checks whether there are any remaining tasks, and quits the event loop
accordingly if none are left.
:param bear:
The bear to clean up state for.'

def _cleanup_bear(self, bear):

    if (not self.running_tasks[bear]):
        resolved_bears = self.dependency_tracker.resolve(bear)
        if resolved_bears:
            self._schedule_bears(resolved_bears)
        del self.running_tasks[bear]
    if (not self.running_tasks):
        resolved = self.dependency_tracker.are_dependencies_resolved
        if (not resolved):
            logging.warning('Core    finished    with    run,    but    it    seems    some    dependencies    were    unresolved:    {}.    Ignoring    them,    but    this    is    a    bug,    please    report    it    to    the    developers.'.format(',    '.join((((repr(dependant) + '    depends    on    ') + repr(dependency)) for (dependency, dependant) in self.dependency_tracker))))
        self.event_loop.stop()
