Skip to content

Warn on small con_pool_size during custom initalization of Updater #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions telegram/ext/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ def __init__(self,
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
Expand All @@ -107,7 +115,7 @@ def __init__(self,
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
Expand All @@ -121,7 +129,6 @@ def __init__(self,
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
Expand Down
7 changes: 7 additions & 0 deletions telegram/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(self,
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',
Expand Down Expand Up @@ -126,6 +128,11 @@ def __init__(self,

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()

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy