From 6b457bada5bb810012309b8380aef0e48c9c7e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Tue, 31 May 2016 13:45:43 +0200 Subject: [PATCH] use keepalive for connection pool --- telegram/utils/request.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/telegram/utils/request.py b/telegram/utils/request.py index f4c2901e4..4b923df4b 100644 --- a/telegram/utils/request.py +++ b/telegram/utils/request.py @@ -19,9 +19,11 @@ """This module contains methods to make POST and GET requests""" import json +import socket import certifi import urllib3 +from urllib3.connection import HTTPConnection from telegram import (InputFile, TelegramError) from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest @@ -35,10 +37,14 @@ def _get_con_pool(): return _CON_POOL global _CON_POOL - _CON_POOL = urllib3.HTTPSConnectionPool(host='api.telegram.org', - maxsize=CON_POOL_SIZE, - cert_reqs='CERT_REQUIRED', - ca_certs=certifi.where()) + _CON_POOL = urllib3.HTTPSConnectionPool( + host='api.telegram.org', + maxsize=CON_POOL_SIZE, + cert_reqs='CERT_REQUIRED', + ca_certs=certifi.where(), + socket_options=HTTPConnection.default_socket_options + [ + (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), + ]) return _CON_POOL