diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 64a57a6..cbedb60 100644 --- a/davtelepot/__init__.py +++ b/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.3" +__version__ = "2.8.4" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/api.py b/davtelepot/api.py index cb5a980..6dd0960 100644 --- a/davtelepot/api.py +++ b/davtelepot/api.py @@ -81,6 +81,7 @@ class TelegramBot: All mirrored methods are camelCase. """ + _loop = None app = aiohttp.web.Application() sessions_timeouts = { @@ -99,6 +100,9 @@ class TelegramBot: def __init__(self, token): """Set bot token and store HTTP sessions.""" + if self.loop is None: + self.__class__._loop = asyncio.new_event_loop() + asyncio.set_event_loop(self.loop) self._token = token self.sessions = dict() self._flood_wait = 0 @@ -111,6 +115,11 @@ class TelegramBot: 0: [] } + @property + def loop(self): + """Telegram API bot token.""" + return self.__class__._loop + @property def token(self): """Telegram API bot token.""" diff --git a/davtelepot/bot.py b/davtelepot/bot.py index c91f608..e70dd3b 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -3434,8 +3434,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): """ logging.info(message) cls.final_state = final_state - loop = asyncio.get_running_loop() - loop.stop() + cls._loop.stop() return @classmethod @@ -3461,8 +3460,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): cls.local_host = local_host if port is not None: cls.port = port - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) + loop = cls._loop try: loop.run_until_complete(cls.run_preliminary_tasks()) except Exception as e: