From 662191eca9fa38172e541d9eaa7f217301aaef19 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 22 May 2021 20:25:58 +0000 Subject: [PATCH] Fix crash as soon as first cl or dl token was acquired --- PFERD/__main__.py | 5 ++--- PFERD/pferd.py | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/PFERD/__main__.py b/PFERD/__main__.py index 9a307b2..0e84e34 100644 --- a/PFERD/__main__.py +++ b/PFERD/__main__.py @@ -117,12 +117,11 @@ def main() -> None: try: pferd = Pferd(config) + asyncio.run(pferd.run()) except ConfigOptionError as e: + log.unlock() log.error(str(e)) exit(1) - - try: - asyncio.run(pferd.run()) except KeyboardInterrupt: log.unlock() log.explain_topic("Interrupted, exiting immediately") diff --git a/PFERD/pferd.py b/PFERD/pferd.py index 20c770f..4aee043 100644 --- a/PFERD/pferd.py +++ b/PFERD/pferd.py @@ -20,9 +20,6 @@ class Pferd: self._authenticators: Dict[str, Authenticator] = {} self._crawlers: Dict[str, Crawler] = {} - self._load_authenticators() - self._load_crawlers() - def _load_authenticators(self) -> None: for name, section in self._config.authenticator_sections(): log.print(f"[bold bright_cyan]Loading[/] {escape(name)}") @@ -46,6 +43,12 @@ class Pferd: self._crawlers[name] = crawler async def run(self) -> None: + # These two functions must run inside the same event loop as the + # crawlers, so that any new objects (like Conditions or Futures) can + # obtain the correct event loop. + self._load_authenticators() + self._load_crawlers() + for name, crawler in self._crawlers.items(): log.print("") log.print(f"[bold bright_cyan]Running[/] {escape(name)}")