MCPcopy Create free account
hub / github.com/eternnoir/pyTelegramBotAPI / _process_polling

Method _process_polling

telebot/async_telebot.py:424–517  ·  view source on GitHub ↗

Function to process polling. :param non_stop: Do not stop polling when an ApiException occurs. :param interval: Delay between two update retrivals :param timeout: Request connection timeout :param request_timeout: Timeout in seconds for long polling (see API

(self, non_stop: bool=False, interval: int=0, timeout: int=20,
            request_timeout: int=None, allowed_updates: Optional[List[str]]=None)

Source from the content-addressed store, hash-verified

422 return error_interval
423
424 async def _process_polling(self, non_stop: bool=False, interval: int=0, timeout: int=20,
425 request_timeout: int=None, allowed_updates: Optional[List[str]]=None):
426 """
427 Function to process polling.
428
429 :param non_stop: Do not stop polling when an ApiException occurs.
430 :param interval: Delay between two update retrivals
431 :param timeout: Request connection timeout
432 :param request_timeout: Timeout in seconds for long polling (see API docs)
433 :param allowed_updates: A list of the update types you want your bot to receive.
434 For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types.
435 See util.update_types for a complete list of available update types.
436 Specify an empty list to receive all update types except chat_member (default).
437 If not specified, the previous setting will be used.
438
439 Please note that this parameter doesn't affect updates created before the call to the get_updates,
440 so unwanted updates may be received for a short period of time.
441
442 :return:
443
444 """
445
446 if not non_stop:
447 # show warning
448 logger.warning("Setting non_stop to False will stop polling on API and system exceptions.")
449
450 self._user = await self.get_me()
451
452 logger.info('Starting your bot with username: [@%s]', self.user.username)
453
454 self._polling = True
455
456 error_interval = 0.25
457
458 try:
459 while self._polling:
460 try:
461 updates = await self.get_updates(offset=self.offset, allowed_updates=allowed_updates, timeout=timeout, request_timeout=request_timeout)
462 if updates:
463 self.offset = updates[-1].update_id + 1
464 # Retain a strong reference so the task isn't GC'd mid-execution.
465 task = asyncio.create_task(self.process_new_updates(updates))
466 self._pending_tasks.add(task)
467 task.add_done_callback(self._pending_tasks.discard)
468 if interval: await asyncio.sleep(interval)
469 error_interval = 0.25 # drop error_interval if no errors
470
471 except KeyboardInterrupt:
472 return
473 except asyncio.CancelledError:
474 return
475 except asyncio_helper.RequestTimeout as e:
476 handled = await self._handle_exception(e)
477 if not handled:
478 logger.error('Unhandled exception (full traceback for debug level): %s', self.__hide_token(str(e)))
479 logger.debug(self.__hide_token(traceback.format_exc()))
480
481 if non_stop:

Callers 3

pollingMethod · 0.95
infinity_pollingMethod · 0.95
driverFunction · 0.80

Calls 8

get_meMethod · 0.95
get_updatesMethod · 0.95
process_new_updatesMethod · 0.95
_handle_exceptionMethod · 0.95
__hide_tokenMethod · 0.95
close_sessionMethod · 0.95
addMethod · 0.45

Tested by 1

driverFunction · 0.64