Skip to content

Commit

Permalink
Merge pull request #107 from tchellomello/1.2.5
Browse files Browse the repository at this point in the history
1.2.5
  • Loading branch information
tchellomello authored Mar 6, 2019
2 parents 97278fc + b63a08a commit e8a3a88
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# GNU General Public License for more details.
define([VERSION_MAJOR], [1])
define([VERSION_MINOR], [2])
define([VERSION_FIX], [4])
define([VERSION_FIX], [5])
define([VERSION_NUMBER], VERSION_MAJOR[.]VERSION_MINOR[.]VERSION_FIX)
define([VERSION_SUFFIX], [_master])

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def readme():


setup(name='amcrest',
version='1.2.4',
version='1.2.5',
description='Python wrapper implementation for Amcrest cameras.',
long_description=readme(),
author='Douglas Schilling Landgraf, Marcelo Moreira de Mello',
Expand Down
23 changes: 7 additions & 16 deletions src/amcrest/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import logging
import requests
from requests.adapters import HTTPAdapter
import threading

from amcrest.utils import clean_url, pretty

Expand Down Expand Up @@ -58,9 +57,6 @@ def __init__(self, host, port, user,
MAX_RETRY_HTTP_CONNECTION)
self._timeout_default = timeout_protocol or TIMEOUT_HTTP_PROTOCOL

self._session = {}
self._get_session_lock = threading.Lock()

self._token = self._generate_token()
self._set_name()

Expand Down Expand Up @@ -121,17 +117,12 @@ def __base_url(self, param=""):
def get_base_url(self):
return self._base_url

def _get_session(self, max_retries):
with self._get_session_lock:
try:
return self._session[max_retries]
except KeyError:
session = requests.Session()
adapter = HTTPAdapter(max_retries=max_retries)
session.mount('http://', adapter)
session.mount('https://', adapter)
self._session[max_retries] = session
return session
def get_session(self, max_retries):
session = requests.Session()
adapter = HTTPAdapter(max_retries=max_retries)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session

def command(self, cmd, retries=None, timeout_cmd=None):
"""
Expand All @@ -143,7 +134,7 @@ def command(self, cmd, retries=None, timeout_cmd=None):
retries = retries or self._retries_default
timeout = timeout_cmd or self._timeout_default

session = self._get_session(retries)
session = self.get_session(retries)
url = self.__base_url(cmd)
for loop in range(1, 2 + retries):
_LOGGER.debug("Running query attempt %s", loop)
Expand Down

0 comments on commit e8a3a88

Please sign in to comment.