1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

No asyncio.run()

This commit is contained in:
_run
2021-11-28 01:04:49 +05:00
parent d58336adcb
commit 411c7e915a
12 changed files with 22 additions and 30 deletions

View File

@@ -138,7 +138,7 @@ class AsyncTeleBot:
json_updates = await asyncio_helper.get_updates(self.token, offset, limit, timeout, allowed_updates, request_timeout)
return [types.Update.de_json(ju) for ju in json_updates]
async def polling(self, non_stop: bool=False, skip_pending=False, interval: int=0, timeout: int=20,
def polling(self, non_stop: bool=False, skip_pending=False, interval: int=0, timeout: int=20,
request_timeout: int=20, allowed_updates: Optional[List[str]]=None,
none_stop: Optional[bool]=None):
"""
@@ -167,10 +167,10 @@ class AsyncTeleBot:
non_stop = none_stop
if skip_pending:
await self.skip_updates()
await self._process_polling(non_stop, interval, timeout, request_timeout, allowed_updates)
asyncio.run(self.skip_updates())
asyncio.run(self._process_polling(non_stop, interval, timeout, request_timeout, allowed_updates))
async def infinity_polling(self, timeout: int=20, skip_pending: bool=False, request_timeout: int=20, logger_level=logging.ERROR,
def infinity_polling(self, timeout: int=20, skip_pending: bool=False, request_timeout: int=20, logger_level=logging.ERROR,
allowed_updates: Optional[List[str]]=None, *args, **kwargs):
"""
Wrap polling with infinite loop and exception handling to avoid bot stops polling.
@@ -190,12 +190,12 @@ class AsyncTeleBot:
so unwanted updates may be received for a short period of time.
"""
if skip_pending:
await self.skip_updates()
asyncio.run(self.skip_updates())
self._polling = True
while self._polling:
try:
await self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout,
allowed_updates=allowed_updates, *args, **kwargs)
asyncio.run( self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout,
allowed_updates=allowed_updates, *args, **kwargs) )
except Exception as e:
if logger_level and logger_level >= logging.ERROR:
logger.error("Infinity polling exception: %s", str(e))