Bug fix: use a unique loop
This commit is contained in:
@@ -11,7 +11,7 @@ __author__ = "Davide Testa"
|
|||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "2.8.3"
|
__version__ = "2.8.4"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class TelegramBot:
|
|||||||
|
|
||||||
All mirrored methods are camelCase.
|
All mirrored methods are camelCase.
|
||||||
"""
|
"""
|
||||||
|
_loop = None
|
||||||
|
|
||||||
app = aiohttp.web.Application()
|
app = aiohttp.web.Application()
|
||||||
sessions_timeouts = {
|
sessions_timeouts = {
|
||||||
@@ -99,6 +100,9 @@ class TelegramBot:
|
|||||||
|
|
||||||
def __init__(self, token):
|
def __init__(self, token):
|
||||||
"""Set bot token and store HTTP sessions."""
|
"""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._token = token
|
||||||
self.sessions = dict()
|
self.sessions = dict()
|
||||||
self._flood_wait = 0
|
self._flood_wait = 0
|
||||||
@@ -111,6 +115,11 @@ class TelegramBot:
|
|||||||
0: []
|
0: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def loop(self):
|
||||||
|
"""Telegram API bot token."""
|
||||||
|
return self.__class__._loop
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def token(self):
|
def token(self):
|
||||||
"""Telegram API bot token."""
|
"""Telegram API bot token."""
|
||||||
|
|||||||
@@ -3434,8 +3434,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
"""
|
"""
|
||||||
logging.info(message)
|
logging.info(message)
|
||||||
cls.final_state = final_state
|
cls.final_state = final_state
|
||||||
loop = asyncio.get_running_loop()
|
cls._loop.stop()
|
||||||
loop.stop()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -3461,8 +3460,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
cls.local_host = local_host
|
cls.local_host = local_host
|
||||||
if port is not None:
|
if port is not None:
|
||||||
cls.port = port
|
cls.port = port
|
||||||
loop = asyncio.new_event_loop()
|
loop = cls._loop
|
||||||
asyncio.set_event_loop(loop)
|
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(cls.run_preliminary_tasks())
|
loop.run_until_complete(cls.run_preliminary_tasks())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user