use keepalive for connection pool

This commit is contained in:
Jannes Höke 2016-05-31 13:45:43 +02:00
parent 74283bd414
commit 6b457bada5

View file

@ -19,9 +19,11 @@
"""This module contains methods to make POST and GET requests""" """This module contains methods to make POST and GET requests"""
import json import json
import socket
import certifi import certifi
import urllib3 import urllib3
from urllib3.connection import HTTPConnection
from telegram import (InputFile, TelegramError) from telegram import (InputFile, TelegramError)
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest
@ -35,10 +37,14 @@ def _get_con_pool():
return _CON_POOL return _CON_POOL
global _CON_POOL global _CON_POOL
_CON_POOL = urllib3.HTTPSConnectionPool(host='api.telegram.org', _CON_POOL = urllib3.HTTPSConnectionPool(
maxsize=CON_POOL_SIZE, host='api.telegram.org',
cert_reqs='CERT_REQUIRED', maxsize=CON_POOL_SIZE,
ca_certs=certifi.where()) cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
socket_options=HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
])
return _CON_POOL return _CON_POOL