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: Request connection timeout. :type timeout: :obj:`int` :param long_p
(self, timeout: Optional[int]=20, skip_pending: Optional[bool]=False, long_polling_timeout: Optional[int]=20,
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)
| 1086 | return message |
| 1087 | |
| 1088 | def infinity_polling(self, timeout: Optional[int]=20, skip_pending: Optional[bool]=False, long_polling_timeout: Optional[int]=20, |
| 1089 | logger_level: Optional[int]=logging.ERROR, allowed_updates: Optional[List[str]]=None, |
| 1090 | restart_on_change: Optional[bool]=False, path_to_watch: Optional[str]=None, *args, **kwargs): |
| 1091 | """ |
| 1092 | Wrap polling with infinite loop and exception handling to avoid bot stops polling. |
| 1093 | |
| 1094 | .. note:: |
| 1095 | |
| 1096 | Install watchdog and psutil before using restart_on_change option. |
| 1097 | |
| 1098 | :param timeout: Request connection timeout. |
| 1099 | :type timeout: :obj:`int` |
| 1100 | |
| 1101 | :param long_polling_timeout: Timeout in seconds for long polling (see API docs) |
| 1102 | :type long_polling_timeout: :obj:`int` |
| 1103 | |
| 1104 | :param skip_pending: skip old updates |
| 1105 | :type skip_pending: :obj:`bool` |
| 1106 | |
| 1107 | :param logger_level: Custom (different from logger itself) logging level for infinity_polling logging. |
| 1108 | Use logger levels from logging as a value. None/NOTSET = no error logging |
| 1109 | :type logger_level: :obj:`int`. |
| 1110 | |
| 1111 | :param allowed_updates: A list of the update types you want your bot to receive. |
| 1112 | For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. |
| 1113 | See util.update_types for a complete list of available update types. |
| 1114 | Specify an empty list to receive all update types except chat_member (default). |
| 1115 | If not specified, the previous setting will be used. |
| 1116 | Please note that this parameter doesn't affect updates created before the call to the get_updates, |
| 1117 | so unwanted updates may be received for a short period of time. |
| 1118 | :type allowed_updates: :obj:`list` of :obj:`str` |
| 1119 | |
| 1120 | :param restart_on_change: Restart a file on file(s) change. Defaults to False |
| 1121 | :type restart_on_change: :obj:`bool` |
| 1122 | |
| 1123 | :param path_to_watch: Path to watch for changes. Defaults to current directory |
| 1124 | :type path_to_watch: :obj:`str` |
| 1125 | |
| 1126 | :return: |
| 1127 | """ |
| 1128 | if skip_pending: |
| 1129 | self.__skip_updates() |
| 1130 | |
| 1131 | if restart_on_change: |
| 1132 | self._setup_change_detector(path_to_watch) |
| 1133 | |
| 1134 | while not self.__stop_polling.is_set(): |
| 1135 | try: |
| 1136 | self.polling(non_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout, |
| 1137 | logger_level=logger_level, allowed_updates=allowed_updates, restart_on_change=False, |
| 1138 | *args, **kwargs) |
| 1139 | except Exception as e: |
| 1140 | if logger_level and logger_level >= logging.ERROR: |
| 1141 | logger.error("Infinity polling exception: %s", self.__hide_token(str(e))) |
| 1142 | if logger_level and logger_level >= logging.DEBUG: |
| 1143 | logger.error("Exception traceback:\n%s", self.__hide_token(traceback.format_exc())) |
| 1144 | time.sleep(3) |
| 1145 | continue |
no test coverage detected