Fix crash as soon as first cl or dl token was acquired

This commit is contained in:
Joscha 2021-05-22 20:25:58 +00:00
parent 8fad8edc1e
commit 662191eca9
2 changed files with 8 additions and 6 deletions

View File

@ -117,12 +117,11 @@ def main() -> None:
try: try:
pferd = Pferd(config) pferd = Pferd(config)
asyncio.run(pferd.run())
except ConfigOptionError as e: except ConfigOptionError as e:
log.unlock()
log.error(str(e)) log.error(str(e))
exit(1) exit(1)
try:
asyncio.run(pferd.run())
except KeyboardInterrupt: except KeyboardInterrupt:
log.unlock() log.unlock()
log.explain_topic("Interrupted, exiting immediately") log.explain_topic("Interrupted, exiting immediately")

View File

@ -20,9 +20,6 @@ class Pferd:
self._authenticators: Dict[str, Authenticator] = {} self._authenticators: Dict[str, Authenticator] = {}
self._crawlers: Dict[str, Crawler] = {} self._crawlers: Dict[str, Crawler] = {}
self._load_authenticators()
self._load_crawlers()
def _load_authenticators(self) -> None: def _load_authenticators(self) -> None:
for name, section in self._config.authenticator_sections(): for name, section in self._config.authenticator_sections():
log.print(f"[bold bright_cyan]Loading[/] {escape(name)}") log.print(f"[bold bright_cyan]Loading[/] {escape(name)}")
@ -46,6 +43,12 @@ class Pferd:
self._crawlers[name] = crawler self._crawlers[name] = crawler
async def run(self) -> None: 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(): for name, crawler in self._crawlers.items():
log.print("") log.print("")
log.print(f"[bold bright_cyan]Running[/] {escape(name)}") log.print(f"[bold bright_cyan]Running[/] {escape(name)}")