Queer European MD passionate about IT
Browse Source

Bug fix: asyncio.run cannot take asyncio.gather as coroutine

Davte 1 year ago
parent
commit
12f3a2cc73
2 changed files with 12 additions and 10 deletions
  1. 1 1
      davtelepot/__init__.py
  2. 11 9
      davtelepot/bot.py

+ 1 - 1
davtelepot/__init__.py

@@ -11,7 +11,7 @@ __author__ = "Davide Testa"
 __email__ = "davide@davte.it"
 __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
 __license__ = "GNU General Public License v3.0"
-__version__ = "2.8.1"
+__version__ = "2.8.2"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 

+ 11 - 9
davtelepot/bot.py

@@ -3438,6 +3438,16 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
         loop.stop()
         return
 
+    @classmethod
+    async def run_preliminary_tasks(cls):
+        await asyncio.gather(
+            *[
+                preliminary_task
+                for bot in cls.bots
+                for preliminary_task in bot.preliminary_tasks
+            ]
+        )
+
     @classmethod
     def run(cls, local_host=None, port=None):
         """Run aiohttp web app and all Bot instances.
@@ -3454,15 +3464,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
         try:
             loop = asyncio.new_event_loop()
             asyncio.set_event_loop(loop)
-            asyncio.run(
-                asyncio.gather(
-                    *[
-                        preliminary_task
-                        for bot in cls.bots
-                        for preliminary_task in bot.preliminary_tasks
-                    ]
-                )
-            )
+            loop.run_until_complete(cls.run_preliminary_tasks())
         except Exception as e:
             logging.error(f"{e}", exc_info=True)
         for bot in cls.bots: