diff --git a/redbot/resource/__init__.py b/redbot/resource/__init__.py index eed399e9..6c979a1d 100644 --- a/redbot/resource/__init__.py +++ b/redbot/resource/__init__.py @@ -52,10 +52,6 @@ def __init__(self, config: SectionProxy, descend: bool = False) -> None: self.subreqs = {ac.check_name: ac(config, self) for ac in active_checks} self.once("fetch_done", self.run_active_checks) - def _finish_check() -> None: - self.finish_check(None) - - self.on("fetch_done", _finish_check) self.links: Dict[str, Set[str]] = {} self.link_count: int = 0 self.linked: List[Tuple[HttpResource, str]] = [] # linked HttpResources @@ -64,8 +60,6 @@ def _finish_check() -> None: ) self.response_content_processors.append(self._link_parser.feed_bytes) - # self.show_task_map(True) # for debugging - def run_active_checks(self) -> None: """ Response is available; perform subordinate requests (e.g., conneg check). @@ -74,6 +68,8 @@ def run_active_checks(self) -> None: for active_check in list(self.subreqs.values()): self.add_check(active_check) active_check.check() + else: + self.finish_check() def add_check(self, *resources: RedFetcher) -> None: "Remember a subordinate check on one or more HttpResource instance." @@ -95,14 +91,15 @@ def check_done() -> None: # pylint: enable=cell-var-from-loop - def finish_check(self, resource: RedFetcher) -> None: + def finish_check(self, resource: RedFetcher = None) -> None: "A check is done. Was that the last one?" - try: - self._task_map.remove(resource) - except KeyError: - raise KeyError( # pylint: disable=raise-missing-from - f"* Can't find {resource} in task map: {self._task_map}" - ) + if resource: + try: + self._task_map.remove(resource) + except KeyError: + raise KeyError( # pylint: disable=raise-missing-from + f"* Can't find {resource} in task map: {self._task_map}" + ) tasks_left = len(self._task_map) # self.emit("debug", "%s checks remaining: %i" % (repr(self), tasks_left)) if tasks_left == 0: