From 25a6f2db6684fad1b8f1d7868d744cc04dc90cdb Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Wed, 10 Jul 2024 12:30:25 +0100 Subject: [PATCH] remove deprecated get_event_loop --- perguntations/app.py | 3 +-- perguntations/testfactory.py | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/perguntations/app.py b/perguntations/app.py index 66f6a71..9263caf 100644 --- a/perguntations/app.py +++ b/perguntations/app.py @@ -69,8 +69,7 @@ class App: self._make_test_factory(config["testfile"]) self._db_setup() # setup engine and load all students - # FIXME: get_event_loop will be deprecated in python3. - asyncio.get_event_loop().run_until_complete(self._assign_tests()) + asyncio.run(self._assign_tests()) # command line options: --allow-all, --allow-list filename if config["allow_all"]: diff --git a/perguntations/testfactory.py b/perguntations/testfactory.py index aa887f5..d9d98fd 100644 --- a/perguntations/testfactory.py +++ b/perguntations/testfactory.py @@ -158,7 +158,7 @@ class TestFactory(dict): if qmissing: raise TestFactoryException(f"Could not find questions {qmissing}.") - self.check_questions() + asyncio.run(self.check_questions()) logger.info("Test factory ready. No errors found.") @@ -262,16 +262,14 @@ class TestFactory(dict): # self.check_grade_scaling() # ------------------------------------------------------------------------ - def check_questions(self) -> None: + async def check_questions(self) -> None: """ checks if questions can be correctly generated and corrected """ logger.info("Checking questions...") - # FIXME: get_event_loop will be deprecated in python3.10 - loop = asyncio.get_event_loop() for i, (qref, qfact) in enumerate(self["question_factory"].items()): try: - question = loop.run_until_complete(qfact.gen_async()) + question = await qfact.gen_async() except Exception as exc: msg = f'Failed to generate "{qref}"' raise TestFactoryException(msg) from exc -- libgit2 0.21.2