mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 12:25:45 +01:00
Warn on small con_pool_size during custom initalization of Updater (#793)
fixes #787
This commit is contained in:
parent
5d7c6ad541
commit
ee34d57521
2 changed files with 16 additions and 2 deletions
|
@ -95,8 +95,16 @@ class Updater(object):
|
|||
if (token is not None) and (bot is not None):
|
||||
raise ValueError('`token` and `bot` are mutually exclusive')
|
||||
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
con_pool_size = workers + 4
|
||||
|
||||
if bot is not None:
|
||||
self.bot = bot
|
||||
if bot.request.con_pool_size < con_pool_size:
|
||||
self.logger.warning(
|
||||
'Connection pool of Request object is smaller than optimal value (%s)',
|
||||
con_pool_size)
|
||||
else:
|
||||
# we need a connection pool the size of:
|
||||
# * for each of the workers
|
||||
|
@ -107,7 +115,7 @@ class Updater(object):
|
|||
if request_kwargs is None:
|
||||
request_kwargs = {}
|
||||
if 'con_pool_size' not in request_kwargs:
|
||||
request_kwargs['con_pool_size'] = workers + 4
|
||||
request_kwargs['con_pool_size'] = con_pool_size
|
||||
self._request = Request(**request_kwargs)
|
||||
self.bot = Bot(token, base_url, request=self._request)
|
||||
self.user_sig_handler = user_sig_handler
|
||||
|
@ -121,7 +129,6 @@ class Updater(object):
|
|||
workers=workers,
|
||||
exception_event=self.__exception_event)
|
||||
self.last_update_id = 0
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.running = False
|
||||
self.is_idle = False
|
||||
self.httpd = None
|
||||
|
|
|
@ -86,6 +86,8 @@ class Request(object):
|
|||
sockopts.append((socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 30))
|
||||
sockopts.append((socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 8))
|
||||
|
||||
self._con_pool_size = con_pool_size
|
||||
|
||||
kwargs = dict(
|
||||
maxsize=con_pool_size,
|
||||
cert_reqs='CERT_REQUIRED',
|
||||
|
@ -126,6 +128,11 @@ class Request(object):
|
|||
|
||||
self._con_pool = mgr
|
||||
|
||||
@property
|
||||
def con_pool_size(self):
|
||||
"""The size of the connection pool used."""
|
||||
return self._con_pool_size
|
||||
|
||||
def stop(self):
|
||||
self._con_pool.clear()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue