Wrap polling with infinite loop and exception handling to avoid bot stops polling. .. note:: Install watchdog and psutil before using restart_on_change option. :param timeout: Timeout in seconds for get_updates(Defaults to None) :type timeout: :obj:`int
(self, timeout: Optional[int]=20, skip_pending: Optional[bool]=False, request_timeout: Optional[int]=None,
logger_level: Optional[int]=logging.ERROR, allowed_updates: Optional[List[str]]=None,
restart_on_change: Optional[bool]=False, path_to_watch: Optional[str]=None, *args, **kwargs)
| 333 | await self._process_polling(non_stop, interval, timeout, request_timeout, allowed_updates) |
| 334 | |
| 335 | async def infinity_polling(self, timeout: Optional[int]=20, skip_pending: Optional[bool]=False, request_timeout: Optional[int]=None, |
| 336 | logger_level: Optional[int]=logging.ERROR, allowed_updates: Optional[List[str]]=None, |
| 337 | restart_on_change: Optional[bool]=False, path_to_watch: Optional[str]=None, *args, **kwargs): |
| 338 | """ |
| 339 | Wrap polling with infinite loop and exception handling to avoid bot stops polling. |
| 340 | |
| 341 | .. note:: |
| 342 | Install watchdog and psutil before using restart_on_change option. |
| 343 | |
| 344 | :param timeout: Timeout in seconds for get_updates(Defaults to None) |
| 345 | :type timeout: :obj:`int` |
| 346 | |
| 347 | :param skip_pending: skip old updates |
| 348 | :type skip_pending: :obj:`bool` |
| 349 | |
| 350 | :param request_timeout: Aiohttp's request timeout. Defaults to 5 minutes(aiohttp.ClientTimeout). |
| 351 | :type request_timeout: :obj:`int` |
| 352 | |
| 353 | :param logger_level: Custom logging level for infinity_polling logging. |
| 354 | Use logger levels from logging as a value. None/NOTSET = no error logging |
| 355 | :type logger_level: :obj:`int` |
| 356 | |
| 357 | :param allowed_updates: A list of the update types you want your bot to receive. |
| 358 | For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. |
| 359 | See util.update_types for a complete list of available update types. |
| 360 | Specify an empty list to receive all update types except chat_member (default). |
| 361 | If not specified, the previous setting will be used. |
| 362 | |
| 363 | Please note that this parameter doesn't affect updates created before the call to the get_updates, |
| 364 | so unwanted updates may be received for a short period of time. |
| 365 | :type allowed_updates: :obj:`list` of :obj:`str` |
| 366 | |
| 367 | :param restart_on_change: Restart a file on file(s) change. Defaults to False |
| 368 | :type restart_on_change: :obj:`bool` |
| 369 | |
| 370 | :param path_to_watch: Path to watch for changes. Defaults to current directory |
| 371 | :type path_to_watch: :obj:`str` |
| 372 | |
| 373 | :return: None |
| 374 | """ |
| 375 | if skip_pending: |
| 376 | await self.skip_updates() |
| 377 | self._polling = True |
| 378 | |
| 379 | if restart_on_change: |
| 380 | self._setup_change_detector(path_to_watch) |
| 381 | |
| 382 | while self._polling: |
| 383 | try: |
| 384 | await self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout, |
| 385 | allowed_updates=allowed_updates, *args, **kwargs) |
| 386 | except Exception as e: |
| 387 | if logger_level and logger_level >= logging.ERROR: |
| 388 | logger.error("Infinity polling exception: %s", self.__hide_token(str(e))) |
| 389 | if logger_level and logger_level >= logging.DEBUG: |
| 390 | logger.error("Exception traceback:\n%s", self.__hide_token(traceback.format_exc())) |
| 391 | await asyncio.sleep(3) |
| 392 | continue |
nothing calls this directly
no test coverage detected