Bug fix: use a unique loop

This commit is contained in:
2022-10-12 13:34:01 +02:00
parent 12f3a2cc73
commit f91661927e
2 changed files with 3 additions and 7 deletions

View File

@@ -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.2"
__version__ = "2.8.3"
__maintainer__ = "Davide Testa"
__contact__ = "t.me/davte"

View File

@@ -3461,9 +3461,9 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
cls.local_host = local_host
if port is not None:
cls.port = port
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(cls.run_preliminary_tasks())
except Exception as e:
logging.error(f"{e}", exc_info=True)
@@ -3471,16 +3471,12 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
bot.setup()
asyncio.ensure_future(cls.start_app())
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_forever()
except KeyboardInterrupt:
logging.info("Stopped by KeyboardInterrupt")
except Exception as e:
logging.error(f"{e}", exc_info=True)
finally:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(cls.stop_app())
return cls.final_state